.htaccess ModReWrite help

2019-09-07 07:13发布

I am having some trouble with my ReWrite code. Please note that the .htaccess file is in the subdomain folder (...public_html/subdomain/ )

I am simply trying to rewrite a page request:

http://subdomain.mysite.com/home
http://subdomain.mysite.com/index.php?page=home

My .htaccess file looks like this...

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_])$ /index.php?page=$1

Does anything jump out at you?

3条回答
女痞
2楼-- · 2019-09-07 07:53

I think

RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

is ok ;)

查看更多
We Are One
3楼-- · 2019-09-07 07:57

If you want to use the rules in a .htaccess file, you need to strip the contextual per-directory path prefix from the RewriteRule pattern. If the .htaccess file is located in the document root /, you need to strip the leading /.

Additionally you need to quantify the character set. Otherwise it would only describe one character.

So try this rule:

RewriteRule ^([A-Za-z0-9-_]+)$ index.php?page=$1
查看更多
虎瘦雄心在
4楼-- · 2019-09-07 08:10

Your current rule probably works for urls one character long (after the slash)!

Add a + to signify one or more characters, or a * for zero or more

Try

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_]*)$ /index.php?page=$1
查看更多
登录 后发表回答