simple(?) htaccess rewriting issues
OK I have been messing about with URL rewriting for the last few days and seem to have come to a bit of a dead-end. I have come up with a few solutions that work on some servers and not others, and my hosting company (1and1 - be vary wary of these guys if you choose them as hosts) hasn't been able to help at all.
My problem is this, i want to re-write this URL:
/result.php?section=[section name]&url=[url]
to this (adding a trailing slash if there is none):
/article/[section name]/[url]/
and ALSO
section.php?section=[section name]
to (again adding a trailing slash):
/section/[section name]/
each attempt seems to have different results. currently I am using thhe f开发者_如何学JAVAollowing, which works locally, but on the live server only the 'articles' rewrite works:
RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /article/$1/$2/
RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /result.php?section=$1&url=$2
RewriteRule ^section/([a-zA-Z0-9_-]+)$ /section/$1/
RewriteRule ^section/([a-zA-Z0-9_-]+)/$ section.php?section=$1
Can anyone help me come up with a solution that will work nicely? Thank you in advance, I am really struggling with what seems like something relatively straightforward...
Firstly in order to force the backslash on the end you will need to actually do a redirect...
RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /article/$1/$2/ [R=302,L]
RewriteRule ^section/([a-zA-Z0-9_-]+)$ /section/$1/ [R=302,L]
Note: I use 302 because 301 can be a pain during testing, once everything is working and you are happy with it change it to 301.
The two remaining rules are the rewrites that simply mask/alias the query_string URL, which should look something like this...
RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /result.php?section=$1&url=$2
RewriteRule ^section/([a-zA-Z0-9_-]+)/$ /section.php?section=$1
精彩评论