.htaccess Same rewrite rule for another page doesn't work - regex

I have this lines in my .htaccess file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /account.php?PAGE=$1 [L]
RewriteRule ^([^/]*)$ /pages.php?PAGE=$1 [L]
The problem is with secondary Rule, so when I want to access pages.php it jumps to account.php
What should I do?

You could try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^account-([^/]+)$ account.php?PAGE=$1 [L]
RewriteRule ^pages-([^/]+)$ pages.php?PAGE=$1 [L]

Related

.htacess mod_rewrite slim routing

I have two kinds of routes.
This works:
http://localhost/monitor/test1
This does not:
http://localhost/monitor/test2/test3
Here is my current rule:
RewriteRule (^[^/]*$) public/$1 [L]
I know this one only matches the last slash. How can I change the regex to match both cases?
1st solution: Could you please try following.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/monitor[^/]*/(.*)$
RewriteRule ^.*$ /public/%1 [NC,L]
OR in case you could have any other string other than monitor in REQUEST_URI starting part then please try following.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]*/(.*)$
RewriteRule ^.*$ /public/%1 [NC,L]
2nd solution: Or we can catch values in while writing RewriteRule itself and could reduce 1 RewriteCond which is used in 1st solution here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]*/(.*)$ /public/$1 [NC,L]
OR with monitor matching keyword:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^monitor[^/]*/(.*)$ /public/$1 [NC,L]

htaccess conditional with else RewriteRule

Hello i want to set a RewriteRule checking a url parameter as http://example.com/admin/bla/foo, example:
If my url contains 'admin' then use:
RewriteRule ^(.*)$ index.php [L]
else
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [L,QSA]
I tried:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/?admin$ [OR]
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [L,QSA]
Any help is appreciated.
You can use these rule in site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin(?:/|$) index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [NC,L,QSA]
This assumes there is no .htaccess in admin/ directory.

301 redirect sub page

I want to redirect
http://www.polisheddiamonds.co.nz/blog/category4
to
http://www.polisheddiamonds.co.nz/blog
but the site has html pages and they already works using htaccess redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog(.*)$ /blog.html?page=$1 [L]
any help will be appreciated
Have your rules like this:
RewriteEngine On
RewriteRule ^blog/category4/?$ /blog? [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog(.*)$ /blog.html?page=$1 [L]

mod_rewrite does not redirect to my internal url

i'm trying to solve a mod_rewrite rule for my webshop.
The URL is: localhost/myshop/category1/category2/myproduct.html
The rediret URLshould be: localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
If I try a RewriteRule like this
RewriteRule ^myproduct\.html$ http://localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
nothing happens and the redirect will not appear.
What i'm doing wrong?
my rewrite rules in .htaccess
RewriteBase /myshop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
RewriteRule ^myproduct\.html$ http://localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
I want that myproduct.html redirects immediatly to the configurator link, so i want to implement a RewriteRule
Try re-ordering your rules:
RewriteEngine On
RewriteBase /myshop/
RewriteRule (^|/)myproduct\.html$ /myshop/configurator/product/configure/id/1/s/myproduct/category1/5/ [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]

Rewrite rule with .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ $1.php
RewriteRule ^(.*)\.html$ page.php?title=$1
I see that my rewriting rules are working but depends on the order of execution. If the pages rewrite rule is the first...it works only for the pages.php.
I've also "played" around with the flags but no results up there.
Try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)\.html$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html$ page.php?title=$1 [L,QSA]