Simple .htaccess rewrite to pass 1 parameter

亡梦爱人 提交于 2019-12-18 06:50:57

问题


Can someone please tell me what should my .htaccess file contain to create the following rewrite:

http://www.example.com/success

to call

http://www.example.com/index.php?q=success

回答1:


Try with:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?q=$1 [L]



回答2:


Heres is one way to do it:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*(success)/?$
RewriteRule .* http://www.mysite.com/index.php?q=%1 [L]

UPDATED

This modification allows for any word(s) instead of success in the previous version:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*/(\w+)$
RewriteRule .* http://www.mysite.com/index.php?q=%1 [L]



回答3:


Following code I use for my site

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?q=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?q=$1

or you can write following

RewriteEngine On

RewriteRule ^(.+)$ index.php?q=$1

RewriteRule ^(.+)/$ index.php?q=$1


来源:https://stackoverflow.com/questions/13760521/simple-htaccess-rewrite-to-pass-1-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!