Ad

.htaccess Rule For 2 Different Pages With Same Rewrite URL

- 1 answer

i have 2 pages

like

page1.php and page2.php

in my htaccess

1st rule is

RewriteRule ^([-a-zA-Z0-9]+)/?$ page1.php?seo=$1 [L]

2nd rule is

1st rule is

RewriteRule ^([-a-zA-Z0-9]+)/?$ page2.php?seo=$1 [L]

my rewrite rule is working perfectly for page1...but when i click a link which suppose to be redirect on page2...so it is not redirecting on that page...it redirect to page1 only....plz help

full htaccess code is

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(_assets|_css|_fonts|_includes|_scripts)($|/) - [L]
RewriteRule ^([A-Za-z-\s0-9]+)$ sub-work.php?seo=$1 [L]
RewriteRule ^([A-Za-z-\s0-9]+)$ portfolio.php?seo=$1 [L]
</IfModule>

thanks

Ad

Answer

Since the RewriteRule is the same for both pages, the first one is overwriting the second.

RewriteRule sub-work/([^/]+)/?$ sub-work.php?seo=$1 [L,QSA]
RewriteRule portfolio/([^/]+)/?$ portfolio.php?seo=$1 [L,QSA]

So the urls shoud look like this:

sub-work/value    
portfolio/value
Ad
source: stackoverflow.com
Ad