Simple .htaccess rewrite to pass 1 parameter

2019-02-18 23:03发布

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

3条回答
仙女界的扛把子
2楼-- · 2019-02-18 23:40

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
查看更多
3楼-- · 2019-02-19 00:01

Try with:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?q=$1 [L]
查看更多
迷人小祖宗
4楼-- · 2019-02-19 00:01

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]
查看更多
登录 后发表回答