We are receiving traffic from an important source but they are sending them to our domain with a /? at the end of it. I have tried to redirect with an entry in our .htaccess but this doesn't work:
Redirect /? http://[domain]
RewriteEngine on
RewriteBase /
I also tried backslashing it:
Redirect /\? http://[domain]
RewriteEngine on
RewriteBase /
Anyone know how to get this to work?
You don't need Redirect directive as more advanced mod_rewrite is needed for this case.
Try this rule:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+([^?]*)\?\s [NC]
RewriteRule ^ /%1? [R=302,L]
Related
How can I redirect requests to /index to simply /
RewriteRule ^/index$ / [R=301,L]
Is giving me headaches and causing a bootloop? This is in a new wordpress install.
Any thoughts how I can achieve this?
You can use a rule like this in your root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^/?index/?$ / [L,R=301]
Since you've tagged Wordpress I must tell you to keep this rule right at top (just below RewriteEngine On line).
I need to redirect this:
http://www.mysite.com/pages/addtocart.php?id=XXXX
to this
https://www.mysite.com/checkout/cart/addsku?id=XXXX
Up to now, this is what I have:
RewriteRule ^/pages/addtocart.php?(.*)$ https://www.mysite.com/checkout/cart/addsku?$1 [R=301,L]
But it's not working.
Help?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^pages/addtocart\.php$ https://%{HTTP_HOST}/checkout/cart/addsku [L,R=302,NC]
PS: Query Parameter will automatically be carried over to new URL.
At the moment the users of my website can access files with the following url-schema:
http://www.example.com/dwl/download.php?file=/files/index.rar
Now i want that they can access it with the following schema:
http://www.example.com/dwl/content/files/index.rar
The download.php file is within the dwl directory.
I tried the following .htaccess:
RewriteEngine On
RewriteRule ^file/([^/]*)$ download.php?file=$1 [L]
But when i try it, i get a 404-Error.
Can anybody please help me to write the correct .htaccess-Entry?
If you want to redirect from http://www.example.com/dwl/download.php?file=/files/index.rar to http://www.example.com/dwl/content/files/index.rar, you need this:
RewriteRule ^/dwl/download.php?file=/(.*) /dwl/content/$1 [L]
I think the code you have to use is the following :
RewriteEngine On
RewriteRule ^/dwl/content(/files/[^/]*)$ /dwl/download.php?file=$1
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT/dwl directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /dwl/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dwl/download\.php\?file=([^\s&]+) [NC]
RewriteRule ^ content/%1? [R=301,L]
RewriteRule ^content/(.+)$ download.php?file=$1 [L,QSA,NC]
Some unchangeable hyperlinks on a website point to /folderA/index.php?id=somestuff.
I need to redirect the Request to /folderB/index.php?id=somestuff instead.
I did some experimenting with this but I just can't get it to work, any help is appreciated.
RewriteEngine on
RewriteRule /folderA/index\.php\?id=([\w-]+)$ /folderB/index.php?id=$1
Keep in mind that RewriteRule doesn't match query string and matches only REQUEST_URI without it. Use this code instead:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folderA/(index\.php\?id=[^&\s]+) [NC]
RewriteRule ^ /folderB/%1 [R=302,L]
Assuming that you are not planning on using different get request this should work:
RewriteEngine on
RewriteRule /folderA/index\.php\?id=(.*?)$ /folderB/index.php?id=$1
I have a domain that's not to be used anymore. I want to redirect all from http://www.old.com/ to http://www.new.com/, no matter what page the user's attempted to access on www.old.com.
Doing this:
RewriteEngine on
Redirect 301 / http://www.new.com/
is fine for the root, but other pages would do this:
http://www.old.com/cms -> http://www.new.com/cms
whereas I'd want it to go to the root, no matter what.
From http://www.webconfs.com/how-to-redirect-a-webpage.php I'd say you can use the following configuration
Don't redirect subfolders/files (as you wanted): www.example.com/demo/ -> www.newexampledomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]
Redirect to subfolders/files: www.example.com/demo/ -> www.newexampledomain.com/demo/
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Put this code in your ROOT .htaccess on www.old.com
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteRule ^ http://www.new.com/ [R=301,L]
This rule will externally redirect all www.old.com/* to www.new.com/