1

可能重复:
删除 URL 中的 .php 扩展名

我已将 my 的子目录更改public_html为主目录。目前,mysite.com/alpha/index.php重定向为mysite.com. 这是完美的工作。

同样,我还有另一个文件events.php,即mysite.com/alpha/events.php?eventid=10对应mysite.com/events.php?eventid=10

但是,我想访问上面的路径mysite.com/events/10/而不是mysite.com/events.php?eventid=10. 为此,我再次修改了文件,但无法加载dynamic URLs. 例如,当我将鼠标悬停在链接上时,它会显示

`mysite.com/events/14` 
`mysite.com/events/15` 
`mysite.com/events/16` 
`mysite.com/events/17`

等等[这就是我想要的]但是点击它[如果我点击mysite.com/events/14悬停时显示的链接],它会打开一个页面mydomain.com//alpha/events.php/14/14?eventid=并且页面不会从sql表格中获取任何内容。

我的 .htaccess 文件:

# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$3
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/alpha/
# Don't change these line.'
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /alpha/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ alpha/index.php [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
4

1 回答 1

1

你的 apache 配置的第 7 行应该更像:

RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$2 [L]
于 2013-01-21T20:39:27.373 回答