Reputation: 598
So I'm trying to rewrite some urls for a website I'm working on. The rewrite files read as:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /NetbeansProjects/App/
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteRule ^/*$ index.php?page=index [NC]
RewriteRule ^([webapp/]+)/([main/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
RewriteRule ^([webapp/]+)/([dashboard/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
RewriteRule ^([webapp/]+)/([search/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
RewriteRule ^([search/]+)/?$ /NetbeansProjects/App/index.php?page=college_$1 [NC,QSA]
RewriteRule ^([webapp/]+)/([apply/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
RewriteRule ^([webapp/]+)/(.*)/([main/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$3&uni=$2 [NC,QSA]
RewriteRule ^([webapp/]+)/(.*)/([apply/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$3&uni=$2 [NC,QSA]
RewriteRule ^([webapp/]+)/(.*)/?$ /NetbeansProjects/App/index.php?page=index [NC,QSA]
RewriteRule ^about/?$ index.php?page=about [NC]
RewriteRule ^webapp/?$ index.php?page=college_no_login [NC]
RewriteRule ^faq/?$ index.php?page=faq [NC]
RewriteRule ^contact/?$ index.php?page=contact [NC]
RewriteRule ^planner/?$ index.php?page=planner [NC]
The main issue is when I pass my url as:
http://www.example.com/webapp/dash or http://www.example.com/webapp/sos
For some reason it redirects wrongly. The localserver is passing this line as true:
RewriteRule ^([webapp/]+)/([dashboard/]+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
Which should not be the case. I was able to detect that using this website: http://martinmelin.se/rewrite-rule-tester/
UPDATE: This code seems to be working as desired for now
RewriteRule ^(webapp+)/(dashboard+)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
on each line I removed '[', ']'
Upvotes: 2
Views: 37
Reputation: 4628
You have a mistake in your regexes. The [abc]
expression stands for one of a set of characters.
This means that [dashboard/]
matches any of "d", "a", "s", etc. so [dashboard/]+
matches any string that consist of any number of "d", "a", "s", etc. but at least one of them altogether.
You need to remove the []
. For grouping, use ()
- however I believe you don't need it in this case:
(foo/)+
Same for [webapp/]
, so the rule becomes:
RewriteRule ^(webapp/)/(dashboard/)/?$ /NetbeansProjects/App/index.php?page=$1_$2 [NC,QSA]
Upvotes: 2