2013-01-21 129 views
1

可能重复:
Removing .php extension in URLs删除扩展名为.php和 “ID = XYZ?”

我已经改变了我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

@TomWalters:这个问题还张贴由我。这是为了删除'.php'的扩展名,它的确如此。这是为了纠正'sql'提取,因为我面临困难。 – xan

+0

我不认为这个问题与SQL有任何关系 –

回答

1

你的Apache配置的7号线应该更像:

RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$2 [L] 
+0

现在显示'sql'字段,尽管地址栏中的URL仍然是:http://www.tryst-iitd.com//13/events。 php?eventid = 25' – xan

+0

Apache在你的情况下不会改变URL,它只是重写它。你在其他地方编写错误的URL。 –