【问题标题】:Getting Value and redirect with htaccess使用 htaccess 获取价值和重定向
【发布时间】:2014-05-25 00:40:58
【问题描述】:

我想将http://example.com/search/search.php?q=videos 重定向到http://example.com/search/videos

我尝试这样做,但它不起作用。这是我的 htaccess 文件:http://example.com/search/.htaccess

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On
RewriteBase /search/

RewriteRule ^([^/]+)(?:/[^/]+)?/?$ search.php?q=$1 [L,QSA]

RewriteRule ^([^/]+)/[^/]+/([0-9]+)/?$ search.php?q=$1&p=$2 [L,QSA]

RewriteRule ^search/(.*)$ load.php?q=$1 [L]

最后一个RewriteRule 不起作用.. 如何解决它.. 帮助.. 谢谢RewriteRule ^search/(.*)$ load.php?q=$1 [L]

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    /search/.htaccess中使用此代码:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /search/
    
    RewriteCond %{THE_REQUEST} /search\.php\?q=([^\s&]+) [NC]
    RewriteRule ^ %1? [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    RewriteRule ^([^/]+)/?$ search.php?q=$1 [L,QSA]
    
    RewriteRule ^[^/]+/([0-9]+)/?$ search.php?q=$1&p=$2 [L,QSA]
    

    【讨论】:

    • 不能在搜索文件夹中使用?
    • 如果你想在搜索文件夹中,那么让我更改代码
    • 不重定向这个:(example.com/search/search.php?q=videos
    • 您需要在浏览器中输入:http://example.com/search/videos 而不是search.php URL。
    • 不,我想要这个链接 example.com/search/search.php?q=videos 重定向到 example.com/search/videos 这样的..
    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 2015-04-27
    • 2019-03-26
    • 1970-01-01
    相关资源
    最近更新 更多