为什么这个干净的URL的.htaccess代码不起作用?

时间:2021-06-05 20:41:26

I want to make a a URL that currently reads:

我想创建一个当前读取的URL:

www.site.com/events/event.php?event_id=_n_ (where n is a number, naturally)

www.site.com/events/event.php?event_id=_n_(其中n是数字,当然)

Read simply:

www.site.com/events/

I have the following code in my .htaccess file

我的.htaccess文件中有以下代码

RewriteEngine On
RewriteRule ^events/([a-zA-Z0-9]+)$ event.php?event_id=$1

But it doesn't seem to make any difference, regardless of whether I put the file in the root or the events directory. Any ideas?

但无论我是将文件放在根目录还是事件目录中,它似乎没有任何区别。有任何想法吗?

1 个解决方案

#1


0  

Place these 2 rules in your DOCUMENT_ROOT/events/.htaccess file:

将这两个规则放在DOCUMENT_ROOT / events / .htaccess文件中:

RewriteEngine On
RewriteBase /events/

RewriteCond %{THE_REQUEST} /event\.php\?event_id=([0-9]+) [NC]
RewriteRule ^ %1? [R=301,L]

RewriteRule ^([0-9]+)/?$ event.php?event_id=$1 [L,QSA,NC]

#1


0  

Place these 2 rules in your DOCUMENT_ROOT/events/.htaccess file:

将这两个规则放在DOCUMENT_ROOT / events / .htaccess文件中:

RewriteEngine On
RewriteBase /events/

RewriteCond %{THE_REQUEST} /event\.php\?event_id=([0-9]+) [NC]
RewriteRule ^ %1? [R=301,L]

RewriteRule ^([0-9]+)/?$ event.php?event_id=$1 [L,QSA,NC]