我已将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]
答案 0 :(得分:1)
apache配置的第7行应该更像:
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$2 [L]