I'm trying to rewrite requests such as:
/98fj3JHgf-83j/
which would show that folder's index.html, to:
/98fj3JHgf-83j/rewritten.html
but ONLY for a certain IP address. I'd rather put the .htaccess for this in the site root and forget about it, as the subfolder can be anything (not quite anything - a random string of uppercase and lowercase letters, numbers and dashes).
What I've got just now works, but I have to place the .htaccess in each subfolder: -
RewriteEngine On
# requests from 12.34.56.78 get rewritten.html instead of index.html
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.78$
RewriteRule ^index.html$ rewritten.html
which is not ideal. A single .htaccess in the root would be great, so I'm guessing a little regex in the above somewhere?
Any help much appreciated!
Try this :
RewriteEngine On
# requests from 12.34.56.78 get rewritten.html instead of index.html
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.78$
RewriteRule ^([A-Za-z0-9-/]*)?index.html$ /$1rewritten.html
Related
I'm trying to redirect URLs with .htaccess in order to be able to make this:
request: http://www.example.org/business/businesswhatever/
redirect: http://www.example.org/businessgrowing/businesswhatever/
The more close I am of reaching the solution is to apply this code:
RewriteRule ^(.*)example\.org/businessgrow/(.*)$ $example.org/businessgrowing/$2 [R=301,L]
but it does not work at all. Validator doesn't check a thing, the only way to validate is if I omit http:// part of the URL.
I need to use hostname as part of the regex because some changes were made and now businessgrow is inside this path: www.example.org/corp/businessgrow, so I need to take part of the hostname in the regex in order to distingish between example.org/businessgrow (it must be a 404) and example.org/corp/businessgrow (200 OK)
I'm using this checker http://htaccess.madewithlove.be/ in order to test before deploying the solution. I tried to remove a slash from http:// (because I was unable to think anything else, I already tried anything) and it worked, but validator (I mean, it doesn't skip validation) outputs 3 slashes like this http:///www.example.org/en/businessgrow/businesswhatever/
If I input the URL without http:// code above works perfectly, but Apache doesn't recognise it and website is unable to show a single page.
I'm using Debian wheezy server and I'm using Wordpress, i took care of write this line just below REwriteBase line, so my .htacces is like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)example\.org/businessgrow/(.*)$ $1example.org/businessgrowing/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I would appreciate if anybody gives me a clue in order to solve this, I think there's some mistake with validation process but I can't find it.
Thanks so much for your time!
btw, sorry about my english..
You don't want the hostname as part of the regex, only the request URI path is used to match. Try:
RewriteCond %{HTTP_HOST} example\.org$ [NC]
RewriteRule ^businessgrow/(.*)$ /businessgrowing/$1 [R=301,L]
I have many URLs like this:
http://blog.domain.org/blog/bid/365332/a-page-here
The number folder after "bid" changes and is random for every URL and "a-page-here" is different for every URL.
I need the regex to direct this type of URL to the following:
http://www.domain.org/blogs/a-page-here
Any help is appreciated as I do not know where to begin with this regex expression.
In the document root of your "blog.domain.org" domain, add:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.domain\.org$ [NC]
RewriteRule ^blog/bid/[0-9]+/(.*)$ http://www.domain.org/blogs/$1 [L,R]
to redirect.
Sorry for this probably very noob-style question, but I just can't get it to work.
Here's my current .htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^_res/.*$ - [L] # all URLs beginning with "_res" are not changed.
# put new fancy rule doing what I want here...
RewriteRule . index.php [L] # all other URLs are redirected to index.php
</IfModule>
This works fine. It's redirecting all urls except the ones starting with "_res/" to index.php.
What I need now is that all URLs matching "[anypath]/video/[anyfilename].mp4" will be rewritten to "content/[anypath]/video/[anyfilename].mp4" (which is the actual path of this file on the server - I can't use x-sendfile on this shared web space, thus I need to rewrite large file urls to their actual server locations to avoid php's fileread-function).
From my understanding of these RewriteRules, I think I have to place this rule just before the last one.
Unfortunately my regexp-expertise is practically non-existent.
What I thought should work is this:
RewriteRule ^(.*)/video/(^/*)\.mp4$ content/$1/video/$2.mp4 [L]
The regexp should mean "starts with any amount of any characters, followed by "/video/", followed by any amount of any characters which are not '/' and ends with ".mp4".
When I insert this into my .htaccess right before the last rule, urls ending with "/video/myvid.mp4" are still rewritten to index.php.
You see me clueless. Any suggestions?
Thanks alot in advance!
I think you want:
RewriteCond %{REQUEST_URI} !^/content/
RewriteRule ^(.*)/video/([^/]+)\.mp4$ content/$1/video/$2.mp4 [L]
And you want to add this rule above the one that routes to index.php
Trying to do a simple URL rewrite with .htaccess but it does not seem to be working.
Want to access http://www.example.com/shop/index.php?route=information/information&information_id=11
using the URL http://www.example.com/MyGreatClub2013
This is what I have in my .htaccess which is stored at the www.example.com root level
RewriteEngine On
RewriteRule ^/MyGreatClub2013$ /shop/index.php?route=information/information&information_id=11 [NC,L]
Am I doing something stupidly wrong?
Remove leading slash:
RewriteEngine On
RewriteRule ^MyGreatClub2013/?$ /shop/index.php?route=information/information&information_id=11 [NC,L,QSA]
mod_rewrite rules when used in .htaccess don't match leading forward slash as .htaccess is per directory.
Here's a decent guide: http://www.javascriptkit.com/howto/htaccess.shtml
Hope it helps.
I'm trying to edit my .htaccess file to do the following:
1) Determine if the HTTP_HOST is not my own domain, example.com
2) Determine if it is otherdomain.com/admin/_anything_here_
/admin/ is the specific folder I am looking for, then I don't care what comes after it (but I do need to keep it there). So basically anything that has /admin/ as the first folder and isn't example.com should rewrite to otherdomain.com/admin/_anything_still_here_
It's my understanding that using (.*)$ will "store" the _anything_here_ part and allow me to use it with $1.
I have this so far but it isn't working fully:
RewriteCond ^%{HTTP_HOST}+(/admin.*)$ !^([^.]+\.)*example\.com+(/admin.*)
RewriteRule (.*)$ rewrite/to/here$1/ [L]
Try adding the following to the .htaccess file in the root directory of your site.
You need to replace somefolder with the actual folder you want to rewrite to
RewriteEngine on
RewriteBase /
#if its not example.com
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
#if its admin folder, rewrite it to somefolder
RewriteRule ^(admin/.*)$ somefolder/$1[L,NC]
The above assumes that otherdomain.com and example.com are on the same server with the same root folder.