The is my real folder scheme:
ROOT
index.html
news.html
+articles
|-obama.html
|-oil.html
I want some htaccess rule so if people go to domain.com/obama.html the server will fetch the one in the articles folder without redirecting.
If some one goes to domain.com/index.html will still fetchs the one in the articles even if there is an index in the ROOT.
Thanks
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond articles/%{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ articles/$1 [QSA]
RewriteRule .* articles/$1 [L,QSA]
Why don't you just use:
# RewriteRule /obama.html$ /articles/obama.html [L]
RewriteCond %{REQUEST_URI} !^/{index,news}.html$
RewriteRule (.*)$ /articles/$1 [L]
?
Related
I want to to redirect access to mysite.com/mydir/, to mysite.com/mydir/index.html
There is a .htaccess config file inside the mydir but it doesn't work as expected:
RewriteCond %{REQUEST_URI} ^/
Rewriterule ^(.*)$ index.html [L,R=301]
Now when I go to mysite.com/mydir/ , I am redirected to:
mysite.com/mydir/C:/wamp/www/mysite/index.html
and If use instead:
Rewriterule ^(.*)$ /index.html [L,R=301]
I am redirected to
mysite.com/index.html
Only thing that works is:
Rewriterule ^$ /mydir/index.html [L,R=301]
but I don't want to hardcode mydir, because this .htaccess might be used in another directory. Could this be solved in a modular way?
You can try with the following (.htaccess file stored in mydir):
RewriteEngine on
RewriteBase /mydir/
RewriteCond %{REQUEST_URI} ^/mydir/$ [NC]
RewriteRule ^ index.html [R=301,L]
I haven't been able to test this since I don't have apache installed locally, but the problem is that you are not appending the group in the parens to the start of the url, if you try
Rewriterule ^(.*)$ $1/index.html [L,R=301]
Then it should will prepend what ever the characters at the start of your URL are i.e. mydir/ before index.html
Try this
RewriteCond %{REQUEST_URI} /$
Rewriterule (.*) http://%{HTTP_HOST}%{REQUEST_URI}index.html [L,R=301]
This is my current .htaccess file:
RewriteEngine On
RewriteBase /application/
RewriteRule (.*)/css/(.*).css www/$1/css/$2.css
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?p=$1
So my end goal here is to have
http://localhost/application/guestbook/css/style.css
forwarded to
/application/www/guestbook/css/style.css
It's almost working, yet when im dumping $_GET i can see that the url he's looking for is
www/www/guestbook/css/style.css
Can someone tell me why its having 2times www/ ? And how can I fix it?
Here is one way to do it:
UPDATED
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*/(\w+/\w+/\w+\.css)$
RewriteRule .* application/www/%1 [L]
Will redirect this:
http://localhost/application/anything1/anything2/anything3.css to
http://localhost/application/www/anything1/anything2/anything3.css
I have url
http://www.url.com/business/index.php?biz=andrewliu
I'm trying to accomplish so it will be
http://www.url.com/business/andrewliu
I tried to have this:
RewriteRule ^/?([a-z0-9_-]+)/?$ /index.php?biz=$1 [L]
or
RewriteRule ^/?([a-z0-9_-]+)/?$ /business/index.php?biz=$1 [L]
doesn't work?
Help me?
Edit:
I have this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
prior to the rewriterule
That depends in which directory your .htaccess file is.
For the root directory try this one:
RewriteRule ^/?business/([a-zA-Z0-9_-\.]+)/?$ /business/index.php?biz=$1 [L]
If your .htaccess file is in the business directory that of your statments should work fine:
RewriteRule ^/?([a-zA-Z0-9_-\.]+)/?$ /index.php?biz=$1 [L]
RewriteRule ^business/([_0-9a-zA-Z-]+)/?$ business/index.php?b=$1 [L]
It's not clear from your examples whether you want "biz" or "business" or "b". I'm taking a guess that you want "biz", in which case your rule should be:
RewriteRule business/(.*) /index.php?biz=$1 [L]
Or maybe you want:
RewriteRule ([^\/]*)/(.*) /index.php?$1=$2 [L]
Quick question, and I've seen it asked hundreds of times, but I just can't seem to get it to work (shame on me).
I'm trying to redirect anything other than index.php to view.php?id=$1 where $1 is anything other than index.php - but I can't seem to get it to work.
For example:
http://domain.com/ should use index.php
http://domain.com/index.php as should this
but..
http://domain.com/sdgoi3 should use http://domain.com/view.php?id=sdgoi3 etc
I've tried a few things and gone down through the questions above but to no avail.
Anyone got a solution? Appreciated.
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^$ /index.php [L]
RewriteRule ^index\.php - [L]
RewriteRule ^view\.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /view.php?id=$1 [L]
The logic here is:
if the request URI is / rewrite to index.php
if the request URI starts with index.php, don't change and pass through
if the request URI starts with view.php, don't change and pass through
if the request is to a non-existing file or directory, pass to view.php with the id param
Maybe something like :
RewriteCond %{REQUEST_URI} !^index\.php
RewriteCond %{REQUEST_URI} !^view\.php
RewriteRule ^(.*)$ view.php?id=$1 [L]
?
I have 1 subfolder located at my root folder:
/root/task6/index.php
And I need to change urls www.andriussulcas.prinusprojects.lt/task6/index.php?p=naujienos&title=title to www.andriussulcas.prinusprojects.lt/task6/naujienos/title
I've been trying to do this for some time now and all my efforts weren't successful.
While searching for answer, I started thinking that maybe my mod_rewrite wasn't activated. But later on I found how to redirect my web site root to subdirectory, where all my files are. So mod_rewrite works.
I found some similar answers here, on stackoverflow, like how to "rewrite rule" for a sub-sub-directory? .htaccess/php but for some reason it doens't work for me.
Here's my .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?andriussulcas.akademija.prinusprojects.lt$
RewriteCond %{REQUEST_URI} !^/task6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /task6/$1
RewriteCond %{HTTP_HOST} ^(www.)?andriussulcas.akademija.prinusprojects.lt$
RewriteRule ^(/)?$ task6/index.php?p=naujienos [L]
RewriteRule ^naujienos/([A-Za-z0-9-]+)?$ index.php?p=naujienos&title=$1 [L]
.htaccess file is located at my root directory, and there are no other .htaccess files at subdirectories.
All help is much appreciated.
Try replacing your last rule with this:
RewriteCond %{HTTP_HOST} ^(www.)?andriussulcas.akademija.prinusprojects.lt$
RewriteRule ^naujienos/([A-Za-z0-9-]+)$ /task6/index.php?p=naujienos&title=$1 [L]