【问题标题】:URL rewriting messes up main directoryURL重写弄乱了主目录
【发布时间】:2014-08-04 19:31:26
【问题描述】:

所以我有这个网址

http://localhost/site/

我还有另一个文件使它看起来像这样

http://localhost/site/info.php?url=website

我把它变成了

http://localhost/site/info/website.com

Options +FollowSymLinks
RewriteEngine On
    
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
    
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ info.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ info.php?url=$1
    

现在当我转到 http://localhost/site/ 时,我最终得到了

找不到

在此服务器上找不到请求的 URL /info.php。

但我只是想获得索引访问http://localhost/site/ 而不是http://localhost/site/info

【问题讨论】:

  • site/ 匹配正则表达式 ^([a-zA-Z0-9_-]+)/$ ,因此将被重写为 info.php?url=site

标签: php .htaccess url mod-rewrite


【解决方案1】:

也许您只想在 url 以 'site/info/' 开头时重写

我没有尝试过,所以它可能不起作用......

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteEngine On
RewriteRule ^site/info/([a-zA-Z0-9_-]+)$ info.php?url=$1
RewriteRule ^site/info/([a-zA-Z0-9_-]+)/$ info.php?url=$1

另外,您确定要在重写时删除 .com...? http://localhost/site/info/website.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    相关资源
    最近更新 更多