Use AJAX with .htaccess redirected subdomain - ajax

i am doing subdomain redirection with;
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^.*$ file.php?id=%1 [L]
This turns someid.domain.com to www.domain.com/file.php?id=someid
Everything is ok for now but i am having problem to use AJAX on the page which is posting variables to a file with
$.post('post.php', {ID: ID},
As you know AJAX wont let to use like www.domain.com/post.php but when i write post.php bec. of redirection it searches for someid.domain.com/post.php
This is what i want;
1- Redirect someid.domain.com to www.domain.com/file.php?id=someid
2- Redirect someid.domain.com/post.php to www.domain.com/post.php

Change your RewriteRule line to:
RewriteRule ^/?$ file.php?id=%1 [L]
This way, only requests for / get rewritten to the file.php script, and not everything.

Related

IBM Commerce SEO URL issue with Ajax calls

i am using WCS7 FEP7. i just enabled seo following below steps.
httpd.conf changes
RewriteRule ^/(.*)$ /webapp/wcs/stores/servlet/$1 [PT,NC]
wc-server.xml changes
<SEOConfiguration defaultUrl="" dynamicUrl="true" enable="true">
<context-root-rewrite value="/"/>
</SEOConfiguration>
I have run the keyword generation job..All SEO URLs are coming up nice.but OOB ajax calls are failing.
Add to cart ajax calling is failing..
I see http:///AjaxOrderChangeServiceItemAdd Ajax POST call is being triggered..
I am getting 404 error.
Where as Commerce server needs http:///webapp/wcs/stores/servlet/AjaxOrderChangeServiceItemAdd
I tried to put a rewrite rule to add 'webapp/wcs/stores/servlet' for this particular request..As this is a POST call (parameters in the body), it would not work properly.
RewriteRule /AjaxOrderChangeServiceItemAdd$
/webapp/wcs/stores/servlet/AjaxOrderChangeServiceItemAdd?data=$1
[NC,L]‹
Am i missing something here.?
Please help.
Try this..In the code snipped below, you need to pass your store and catalog ids respectively.
RewriteEngine on
RewriteRule ^/?$ /webapp/wcs/stores/servlet/TopCategoriesDisplay?storeId=<storeId>&catalogId=<catalogId> [L,QSA,PT]
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/sitemap.xml(.gz)?$
RewriteCond %{REQUEST_URI} !^/solr.*$
RewriteCond %{REQUEST_URI} !^/lobtools.*$
RewriteCond %{REQUEST_URI} !^(/)?$
RewriteCond %{REQUEST_URI} !^/webapp.*$
RewriteCond %{REQUEST_URI} !^/wcsstore.*$
RewriteCond %{REQUEST_URI} !^/ConsumerDirectStorefrontAssetStore.*$
RewriteCond %{REQUEST_URI} !^/wps.*$
RewriteCond %{REQUEST_URI} !^/images/.*$
RewriteCond %{REQUEST_URI} !^/favicon\.ico
RewriteRule ^/(.*) /webapp/wcs/stores/servlet/$1?storeId=<storeId>[QSA,PT]
read this below and try it , it is a little different than what you did
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.starterstores.doc/tasks/tsmshortenmadisonsurl.htm
As it's mentioned in
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.starterstores.doc/tasks/tsmshortenmadisonsurl.htm
`If you are specifying a blank context root, use the following format instead:
RewriteEngine on
RewriteRule ^/(?!wcsstore)(.*) /webapp/wcs/stores/servlet/$1 [PT,L]`
The SEO engine should not care if it's an POST request. Data is sent regardless.
Be sure that you've created your AJAX call from wcf:url
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.component-services.doc/refs/rwvwcfurl.htm

Codeigniter redirect solution

Trying to get
www.example.com/home
to go directly to
www.example.com/
What I've tried:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.+)\www.example\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]
What am I doing wrong?
but its website rotating always .
Redirect 301 /home http://www.example.com/
If what you are saying is that you want the index function in your "home" controller to be the default homepage, you can set that in routes.php under the route['default_controller'] parameter. That way you don't need to worry about the redirect at all. If you want to remove /home anytime it's typed in, you can use a mod-rewrite like you do to remove index.php from the uri. Check out the docs for more info http://ellislab.com/codeigniter/user-guide/general/urls.html

mod_rewrtie remap and redirect

what i am trying to do is this:
If url http://example.com/foo/foo.php is called it should be redirected with 301 to http://example.com/bar/foo.php
AND
if url http://example.com/bar/foo.php is called it internally calles the /bar/foo.php script but browser url is not changed (remap).
my rules look like this
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [PT]
But this gives me too many redirects error.
Each rule activated separately works but together they seem to conflict...
You can either match against the actual request:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /foo/foo.php
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [L]
Or prevent rewrite looping altogether:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [L]

Rewrite URL on submit form

I have a search form and when I make a search I get this URL "http://****/video/view/search/?imeto_tam=tarsene" but I want to replace this the "?imeto_tam=tarsene" with the word I search for and my address to look like this - "http://****/video/view/search/tarsene". Generally I use mod_rewrite on my site and it's working for my links but it's not working for the form-s. Could someone tell me how to do it?
RewriteEngine On
RewriteRule ^view/([0-9a-zA-Z\-\(\)]+)/?$ index.php?a=$1 [L]
RewriteRule ^view/([0-9a-zA-Z\-():]+)/([0-9a-zA-Z\-():\.,]+)$ index.php?a=$1&id=$2 [L]
These rules would go into your root .htaccess file and 301 redirect the querystring imeto_tam to the folder and then the next rule would make it get passed to your code (index.php)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?imeto_tam=([^&]+)(&.*)?$ [NC]
RewriteRule ^video/view/search/(index\.php)?$ /video/view/search/%2/? [R=301,L]
RewriteRule ^video/view/search/([^/]+)/$ /video/view/search/index\.php?imeto_tam=$1 [L]

rewriting single url help

I'm trying to rewrite the following url:
index.php?route=checkout/cart
to
/cart
using:
RewriteRule ^index.php?route=checkout/cart$ /basket [L]
However it doesn't seem to work. Anyone know what I'm doing wrong?
Thanks
RewriteRule does only test the URL path. You need RewriteCond to test the query:
RewriteCond %{QUERY_STRING} ^route=checkout/cart$
RewriteRule ^index\.php$ /basket [L,R=301]
The additional R=301 flag will cause an external redirect with the status code 301 (permanent redirect) instead of an internal redirect.
And if you want the other way round:
RewriteRule ^basket$ index.php?route=checkout/cart [L]
You need to send a redirect so that the new URL get reflected in browser address bar. So, add R to the [L].
RewriteRule ^index.php?route=checkout/cart$ /basket [R,L]
If you'd like that searchbots should ignore the "ugly" URL and/or remove it from the indexes and use the new instead, then send a 301 redirect.
RewriteRule ^index.php?route=checkout/cart$ /basket [R=301,L]

Resources