I want to redirect (only) mysite/02B /030 etc to theirsite/02B etc.
What's wrong with this? I have the sense that I'm missing something stupidly obvious. :-/
RewriteCond %(REQUEST_URI) ^0(2B|2Y|2C|2Z|2-|30|33)$
RewriteRule ^(.*)$ http://theirsite/$1 [R=301,NC,L]
Thanks!
The leading slash / is included in the REQUEST_URI variable, so you have to include it also in the regular expression to match the variable.
You may try this complete rule-set instead:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/0(2B|2Y|2C|2Z|2-|30|33) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://theirsite/$1 [R=301,NC,L]
Related
I'm trying to rewrite URLs using htaccess. The idea behind this is quite simple:
Once a visitor visits https://example.com/pineapples, the browser should load https://example.com/index.php?page=pineapples instead while remaining the original URL.
This should only happen when a file exists in /pages/ with the name of the requested URL, in this case pineapples.php.
This also counts for subdirectories: https://example.com/pineapples/flamingos should redirect to https://example.com/index.php?page=pineapples/flamingos when the file exists in /pages/, in this case /pages/pineapples/flamingos.php, where pineapples is a subdirectory.
Now I've tried to do this, but it's very buggy. It doesn't work for subdirectories as explained above, and it seems to work for all the directories, instead of just /pages/.
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} !^/pages(/|$)
RewriteRule ^([^/]+/[^/]+/). /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
If someone please can help me out get this to work, I will be very grateful!
This question has been answered using the following htaccess.
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$
RewriteRule ^(ajax|assets|auth)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
You can't check REQUEST_FILENAME because in your case it has to be in pages
so you may want to try
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteLog /path/to/log
RewriteLogLevel 5
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} !^/pages(/|$)
RewriteRule ^([^/]+/[^/]+/). /$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}pages%{REQUEST_URI}.php -f
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
Also I have enabled rewrite log, so in case it doesn't work, please post the logs your get
I've looked through many questions on here but haven't found one that quite answers my question (could be wrong, feel free to suggest an answer I missed)
How would you write the .htaccess file to send all requests from the folder
example.com/subpage/img to example.com/img and example.com/subpage/js to example.com/js
Where subpage can be any text string
This is the file so far
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (^[A-Za-z]+[\/]?) index.php?page=$1 [L]
Secondly, how could you add a second parameter to the last rule? like index.php?page=$1subpage=$2
Please let me know if this needs to be more specific
Add this rule to your existing code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^[^/]+/((?:img|js)/.*)$ /$1 [L,NC]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)(?:/([a-z]+))?/?$ index.php?page=$1&subpage=$2 [L,NC,QSA]
I'm having an issue with a query string, although I'm not sure what i'm tryign to do is possible.
I have the following url with a search query attached:
subdomain.mysite.com/search/?search=searchquery
but I need it to redirect to the following url including the query string:
subdomain.mysite.com/search/?rs=searchquery
I was wondering if this is possible with a mod_rewrite?
I've tried the following:
RewriteCond %{REQUEST_URI} ^/search/?$
RewriteCond %{QUERY_STRING} ^search=([0-9]*)$
RewriteRule ^(.*)$ http://subdomain.mysite.com/search/?rs=% [L,R=301]
I don't know if my Syntax is incorrect or i'm just barking up the wrong tree. Any help would be awesome.
This is the Start of my HTAccess File - This is a Wordpress site with the rewrite rule provided by user: Amine Hajyoussef:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} ^/search/?$
RewriteCond %{QUERY_STRING} ^search=([^&]*)$
RewriteRule ^(.*)$ /search/?rs=%1 [L,R=301]
</IfModule>
Unfortunately this doesnt appear to work? Any ideas?
you forgot the 1 after %, i have also changed the search string so it can be anything instead of just number.
RewriteCond %{REQUEST_URI} ^/search/?$
RewriteCond %{QUERY_STRING} ^search=([^&]*)$
RewriteRule ^(.*)$ /search/?rs=%1 [L,R=301]
Trying to rewrite former urls to the latter. Rewrite that doesn't work for some reason. How to fix? Thanks.
www.example.com/example-example.html
www.example.com/example-example/
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+-?[a-z]+)/$ /$1.html
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Try this:
RewriteRule ^([a-z-]+)/?$ $1.html
This will silently rewrite a user's request for /example-example/ to an actual file path /example-example.html. No checking is performed to see whether the file path exists, and it will match any request which contains letters and hyphens. If you need more specific constraints, let us know.
I'm trying to redirect all pages to a blog post at URL
example.com/big-changes-for-2013/
(including trailing slash)
I do not want to redirect me, because I'm working on the rest of the site.
This is what I have so far (this is a .htaccess redirect):
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/big-changes-for-2013/$
RewriteCond %{REMOTE_ADDR} !^50\.137\.88\.129
RewriteRule $ /big-changes-for-2013/$ [R=302,L]
The part preventing me from being redirected works. The part thats not working is the redirect itself, which is an infinite loop.
The code above is based off of a combination of this and this.
Any ideas?
Try
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^50\.137\.88\.129
RewriteRule ^(?!big-changes-for-2013/$) /big-changes-for-2013/$ [R=302,L]
The rule regexp is what is a called a negative look-ahead assertion. It means "match anything other than big-changes-for-2013/$".
Solved with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REMOTE_ADDR} !^50\.137\.88\.129
RewriteCond %{REQUEST_URI} !^/(big-changes-for-2013/)
RewriteRule ^(.*) /big-changes-for-2013/ [L,R=301]
</IfModule>