cannot redirect subfolders via htaccess mod_rewrite - .htaccess

i have a htaccess problem
all urls will redirect via access:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?load=content&url=$1
Domain www.domain.de/nicepage will redirect to www.domain.de/index.php?load=content&url=nicepage
Now I would like to redirect 'subfolder':
from www.domain.de/faq/nicefaq to www.domain.de/index.php?load=faqdetail&url=nicefaq
That's what I am try:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?load=content&url=$1
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1
This does not work. everytime i call the page i will redirect to load=content.
Can You help me pls?
thanks in advance and best regards
Maddin

Both RewriteRules match against the same condition. As the first you wrote matches everything, the second is never reached. Just change the order:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1
RewriteRule ^(.*)$ index.php?load=content&url=$1
Hope this helps...

Try this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/+faq [NC]
RewriteRule ^(.*)$ index.php?load=content&url=$1 [L,QSA]

Related

url rewriting not showing index page

I have this htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
DirectoryIndex index.php
RewriteRule ^doit$ doit.php [L]
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
But when i try to go in the index page, everytime showing follow.php page, even doit page show this last one.
Any fix for this issue please ?
Thank's.
RewriteCond technically applies only to the first RewriteRule, so
please try using something like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
#RewriteConds for this rule
RewriteRule ^doit$ doit.php [L]
DirectoryIndex index.php
I hope be useful. Regards.

RewriteRule for Pretty URLs not working

The URLs of my site are of the type
http://localhost/cms2/pages.php?mpage=2
I have written the following .htaccess in order to create pretty URLs, but nothing happens
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)\/$ pages.php?spage=$1 [NC]
Mod-rewite is ennabled and other rewrite rules I've tested work. For example, I have a file called "contact-us.php". I can make it look "mysite.com/contact-us" using the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^(.*)\.html$ $1.php [nc]
Any help would be appreciated.
Thanks in advance.
Sonia
Not working because your regex is incorrect. Use this rule in your root .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/([^./]+)/?$ /cms2/$2.php?spage=$1 [L,QSA]
This will rewrite a pretty URI: /3/page/ to /cms2/page.php?spage=3

language redirect from GET parameter htaccess

I have this code, it redirecs www.example.com?index.php?q=home&lang=en into www.example.com/home. I would like to redirect it into www.example.com/en/home. Is it possible?
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?q=$1&lang=$2 [L,QSA]
RewriteRule ^([^/]*)(.*)$ $1[L,QSA]
Thanks in advance
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ /index.php?q=$2&lang=$1 [L,QSA]

decide page based on number of parameters - htaccess url rewrite

i am writing RewriteRule(s) on htaccess which decides which page it redirect to based on the number of parameters.
for example, "http://mysite.com/tommy"
this will redirect to "mysite.com/user.php?user=tommy"
whereas, "http://mysite.com/tommy/pets"
will redirect to "mysite.com/show.php?user=tommy&category=pets"
note, the first URL has only one parameters and it redirects to user.php and second URL has two parameters and it redirects to show.php instead.
please help, and thanks in advance!
Currently...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)/?(.*)$ category.php?userId=$1&category=$2 [QSA,L]
RewriteRule ^(.*)$ user.php?userId=$1 [QSA,L]
</IfModule>
Done, for anyone else who need this too...
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ category.php?userId=$1&category=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ category.php?userId=$1&category=$2 [L]

.htaccess retrieve from folder if subdomain, not 301 redirecting?

I want my site to just point to /user folder if the request is a subdomain.
If the request is subdomain.site.com/admin, then the site should show the page for subdomain.site.com/user/admin.
The problem with my code is that it makes an 301 redirect instead of just keeping the url-address.
My code look like this:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se(.*)
RewriteCond %{HTTP_HOST} ^[^.]+.bildsida.se(.*)
RewriteRule ^$ user/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) user/$1 [L]
</IfModule>
And you can try for yourself, go to http://mickes.bildsida.se/admin and see how the address changes to /user/admin. Very disturbing...
You just need a few of the lines you showed to get this working.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} ^.+\.bildsida\.se
RewriteRule ^(.*)$ user/$1 [L]
I adjusted the HTTP_HOST checks because that parameter only looks at the domain name, so you don't need the (.*) at the end. I also removed the checks that look if the file exists or is a directory, since you want everything redirected (no reason to make it possible to access files from other subdomains, for example)
You code can be simplified to these lines : (try them instead)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?bildsida\.se [NC]
RewriteRule ^(.*)$ /user/$1 [QSA,L]
Finally! After days and nights of reading forums and documentations, and testing all possible ways, I got it to work!
Sulotion:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} !^bildsida.se
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ user/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)? user/$1/ [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /(.+)/ user/$1 [QSA]
</IfModule>

Resources