我希望我的网址能够改变 e.g。
website.com/contactus.php?type=buy&property=texas
website.com/contactus.php?type=sell
到
website.com/contactus/buy/texas
website.com/contactus/sell
分别。这就是我到目前为止所做的事情 -
RewriteEngine on
Options +FollowSymLinks
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so file types are hidden
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
Options +MultiViews
Options -Indexes
#makes so GET stuff are hidden
RewriteRule ^contactus/([^/]*)/([^/]*)$ /contactus.php?id=$1&$2 [L,QSA]
我已经阅读了无数的堆栈溢出问题,但关于GET值的一点看起来根本没有用......
-edit-感谢anubhavas的帮助,我设法解决了它:)这里的代码,适合任何人看。
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so php file types are hidden
RewriteRule ^(emailme)/?$ $1.php [L,QSA]
#makes it so GET values are hidden
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]
答案 0 :(得分:1)
这样做:
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so file types are hidden
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(contactus|emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(contactus|emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]