1

I'd like to use .htaccess for url rewrite. In my previous post you have shown me how to do it to the index.php page but now would like to do also for other pages like browser.error.php, etc. To do so I tried to add the last 2 rows in the .htaccess, but unfortunately if I try the link www.mysite/browser-error/ it doesn't work - Return me in the index page.

Options +FollowSymLinks RewriteEngine on RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L,NC] # rule to ignore files and directories from all rewrite rules below RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] RewriteRule ^(.*)/(.*)/(.*)\/?$ index.php?op=$1&idric=$2&sp=$3 [L,QSA,NC] RewriteRule ^(.*)/(.*)\/?$ index.php?op=$1&idric=$2 [L,QSA,NC] RewriteRule ^(.*)\/?$ index.php?op=$1 [L,QSA] #NEW ADDED ROWS RewriteRule ^browser-error/(.*)\/?$ browser.error.php?r=$1 [L] RewriteRule ^browser-error\/?$ browser.error.php [L] 

Where I am doing wrong? How would I go? Thank you

2 Answers 2

2

I would suggest avoid use of .* and use [^/]+ instead with re-ordering of your rules:

Options +FollowSymLinks -MultiViews RewriteEngine on RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L,NC] # rule to ignore files and directories from all rewrite rules below RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] #NEW ADDED ROWS RewriteRule ^browser-error/([^/]+)/?$ browser.error.php?r=$1 [L,QSA,NC] RewriteRule ^browser-error/?$ browser.error.php [L,NC] RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?op=$1&idric=$2&sp=$3 [L,QSA] RewriteRule ^([^/]+)/([^/]+)/?$ index.php?op=$1&idric=$2 [L,QSA] RewriteRule ^([^/]+)/?$ index.php?op=$1 [L,QSA] 
Sign up to request clarification or add additional context in comments.

4 Comments

Seems to be perfect! If you add other rules (comunication.php) I have to make them like those for browser-error? Thanks!
Yes that's correct just add them in the middle before index.php rules.
with same flag ? L, QSA, NC and L, NC?
yes [L,QSA,NC] would be suffice for that as well.
0

You have rules before preceding this rule. That makes your petition change to index.php before your rule is reached. (They all have the L flag that makes them be the LAST rule processed). As they are not restricted to not be applied when url is browser-error, they will run on every ///* or simialr petition.

Then, you should add RewriteCond to negate the browser-error url in your other RewriteRules as this:

Please try, and comment if that´s not what you need of it does not work as expected.

Hope it helps

Options +FollowSymLinks RewriteEngine on RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L,NC] # rule to ignore files and directories from all rewrite rules below RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] RewriteRule ^(.*)/(.*)/(.*)\/?$ index.php?op=$1&idric=$2&sp=$3 [L,QSA,NC] RewriteCond %{REQUEST_URI} !^browser-error\/?(.*)?\/?% RewriteRule ^(.*)/(.*)\/?$ index.php?op=$1&idric=$2 [L,QSA,NC] RewriteCond %{REQUEST_URI} !^browser-error\/?(.*)?\/?% RewriteRule ^(.*)\/?$ index.php?op=$1 [L,QSA] #NEW ADDED ROWS RewriteRule ^browser-error/(.*)\/?$ browser.error.php?r=$1 [L] RewriteRule ^browser-error\/?$ browser.error.php [L] 

4 Comments

Unfortunately nothing works, not even the rewrite url to index.php
i did make a change, sorry (cannot try now here)
Thank you, but the anubhava solution is perfect for me
I was goin to tell you this solution was better (reordering thre rules, and cleaning) +1 for him!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.