Hy!
I'm developing a web site and have a small problem with .htaccess
.
Problem: how to rewrite urls?
From: http://www.mysite.com/index.php?page=about
To: http://www.mysite.com/about/
and
From: http://www.mysite.com/index.php?page=stuff&catId=1
To: http://www.mysite.com/stuff/1/
and
From: http://www.mysite.com/index.php?page=stuff&catId=1#someAnchor
To: http://www.mysite.com/stuff/1/#someAnchor
Currently I'm doing this but it doesn't work! :(
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^page/([开发者_JS百科^/.]+)/([^/.]+)/?$ index.php?page=$1&catId=$2 [L]
</IfModule>
Please help. Thanks in advance, Silvano.
This will do what you want:
#Rewrite /about/ to /index.php?page=about
RewriteRule ^([0-9a-z]+)/?$ index.php?page=$1 [NC,L]
#/stuff/1/ to /index.php?page=stuff&catId=1
RewriteRule ^([0-9a-z]+)/([0-9]+)/?$ index.php?page=$1&catId=$2 [NC,L]
#/stuff/1/#someAnchor to /index.php?page=stuff&catId=1#someAnchor
RewriteRule ^([0-9a-z]+)/([0-9]+)/(#[0-9a-z]+)?$ index.php?page=$1&catId=$2$3 [NC,L]
Works on my local server (WAMP).
What you currently have i your .htaccess
file is not related to your rewrite requests.
Here is what you need:
The first:
RewriteRule ^(.*)/$ index.php?page=$1
The second:
RewriteRule ^(.*)/([0-9]*)$ index.php?page=$1&catId=$2
Be sure to add RewriteEngine on
at the top.
Your server will never get the "#someAnchor" part of the url, because no browser in the world will send this as part of the request. The browser keeps it private.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?page=$1&catId=$2 [L]
精彩评论