tec-4 Posted September 7, 2011 Share Posted September 7, 2011 Hi all, Trying to figure out why the page I'm creating works when I place a trailing slash but 404's when i take it off...trying to get it to not have it. For example, this code: RewriteRule ^([A-Za-z0-9\-+\(\)#%|_,]+-test-page)([A-Za-z0-9\-/+_\(\)]+)$ file.php?city=$1&query=$2 [L] results in: example DOT com/city-test-page/ and if I take off the trailing slash it goes to a 404 but would like it to be the other way around. Also when I take the "([A-Za-z0-9\-/+_\(\)]+)" and "&query=$2" out it works correctly in regards to trailing slash but they query doesn't work. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/246636-quick-htaccess-question-not-have-trailing-slash-after-file-re-write/ Share on other sites More sharing options...
cags Posted September 9, 2011 Share Posted September 9, 2011 What are you expecting the &query part to contain? The simple answer is that with the trailing slash of your URI the second capture group has something to capture (the /), without it it doesn't match anything, meaning your pattern doesn't match so the RewriteRule won't get applied. Something like this would probably be more approriate, as the second capture group doesn't have a required width and will not contain the trailing slash. Alternatively you could write one RewriteRule for 1 'directory' deep and another for 2. RewriteRule ^([A-Za-z0-9-]+-test-page)/?([A-Za-z0-9-]*)$ file.php?city=$1&query=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/246636-quick-htaccess-question-not-have-trailing-slash-after-file-re-write/#findComment-1267260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.