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]
Related
On my CodeIgniter site, I would like to add a specific rewrite rule, so that this url
http://www.exemple.com/cache.manifest
would rewrite to
http://www.exemple.com/controller/manifest
(because Safari 7 seems to only accept .manifest files for ApplicationCache)
So I try to add this line to my htaccess
RewriteRule ^cache.manifest$ controller/manifest
I added it before the other rewrite rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^cache.manifest$ controller/manifest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
But it returns a 404. If I change the line to
RewriteRule ^cache.manifest$ test.html
it works. So the first part on my rule is correct.
If I try to access directly to www.example.com/controller/manifest, it works to, so my url is correct.
I tried also
RewriteRule ^cache.manifest$ index.php/controller/manifest [L]
But it doesn't work either…
Any clue ?
Thanks a lot
I tried some tests on my local server and I think the following might work:
RewriteRule ^cache.manifest$ /index.php/controller/manifest [R,L]
I am not entirely sure if you need the leading "/" or "/index.php", so you
may need to experiment.
You need the [R] flag to force a redirect. In this situation, you want Apache
to look for the string cache.manifest in the URL, and then go to the CI page
controller/manifest.
It appears that you need to explicitly set the redirect.
Please let me know if this works. Good luck!
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.
I just can't seem to be able to run a 301 redirect and rewrite when a specific variable is somewhere inside a dynamic URL.
For example, with any of these URLs:
/movabletype/mt-search.cgi?tag=SOMETHING&limit=20
/some-other-random-content?post=somethinghere&tag=SOMETHING
If tag=SOMETHING is anywhere inside the URL, then redirect to:
/categories/something_here/
Any ideas?! Here's what I have so far - I'm at a loss as to what to put inside the RewriteCond
RewriteCond %{REQUEST_URI}
RewriteRule tag=SOMETHING /categories/something_here/ [L,R=301]
Your rewrite condition requires a left- and right-hand argument. It looks like you want to redirect when a certain URL parameter is present (i.e, tag), so you can use %{QUERY_STRING} in your condition.
Consider the following example:
RewriteCond %{QUERY_STRING} tag=([A-Za-z0-9]+)
RewriteRule ^(.*)$ /categories/$1 [R=301,L]
This should take a URL like /some-other-random-content?post=somethinghere&tag=SOMETHING and redirect it to /categories/SOMETHING.
URL Rewriting for Beginners may be a helpful guide.
I think this is a pretty straight forward question in mod_rewrite:
I got one domain, which needs to redirect to another, but keep any value after last slash (/) in the first URL, over to the second.
domain.com/4433 should transfer to domain.com/folder/?p=4333
Listed for clarity:
From: domain.com/4433
To: domain.com/folder/?p=4333
Any ideas?
Edit:
Did some testing, we found the following solution:
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^([0-9a-z]*)$ /folder/?p=$1 [NC]
sincerely,
- bakkelun
In case you don't really want to redirect but to have pretty URLs, you can use
RewriteEngine On
RewriteRule ^/(.+)$ /folder?p=$1 [L]
This takes everything after the first slash and inserts it at the $1 - but only if there's something after the slash. It doesn't issue a redirect so the users won't notice.
Without any further information, try this:
RewriteEngine on
RewriteRule ^/([^/]+)$ /folder/?p=$1
If you want to use the rule in a .htaccess file, remove the leading slashes.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ domain.com/folder?p=$1 [R=301,L]
Just in case: domain.com = domain1.com and domain2.com? domain1.com should be redirected to domain2.com? Both run on the same server (optional)?
[EDIT:]
If you really only want to do the thing as stated in the comment, then do the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^4433$ http://domain2.com/folder/?p=4433 [R=301,L]
Else, as Benedikt Eger said, or with R=301 if you want real redirection.
Or, if you want it to redirect only on numbers, then do the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^([0-9])+$ http://domain2.com/folder/?p=$1 [R=301,L]
RewriteCond checks, if defined vhost is domain1.com, but not domain2.com, then the rewrite rule is applied, and redirects via HTTP status 301 [R=301] only number strings (0-9)+ consisting of at least one number to the specified URL. [L] makes this the last rule applied.
I have a simple redirect which I just can't get to work and I don't know what's wrong. The server's throwing me a 500 Internal Server Error for no reason I can understand.
I'm trying to achieve the following: if a user types the address www.example.com, it will actually be routed to domain/ subdirectory in my server. So if user requests www.example.com/index.htm, it would fetch the file from /var/www/html/domain/index.htm.
Here's what I have so far:
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^(.*)$ domain/$1 [L]
Mod_rewrite is enabled and functional, as this does work:
RewriteRule ^(.*)$ domain/index.php?$1 [L]
What am I missing here?
You have to exclude the destination you want to redirect to:
RewriteCond %{SERVER_NAME} =www.example.com
RewriteCond $1 !^domain/
RewriteRule ^(.*)$ domain/$1 [L]
Otherwise you will get an infinite recursion since domain/… is also matched by .*.