【问题标题】:htaccess redirect depending on text after /htaccess 重定向取决于 / 之后的文本
【发布时间】:2016-04-11 17:01:23
【问题描述】:

我有一个与 .htaccess 相关的问题,需要重定向帮助。

我有一个目录,其中保存了多个其他目录,其中一个是我的网站目录。

我的 .htaccess 文件已经设置为默认进入我的网站所在的子目录并显示 url,就好像它不在子目录中一样,即“reinhards.co/”,而不是“reinhards .co/reinhards.co"

# BEGIN WordPress
# In Root directory
# WPhtC: Disable directory browsing
Options All -Indexes

RewriteCond %{HTTP_HOST} ^(www.)?reinhards.co$
RewriteCond %{REQUEST_URI} !^/reinhards.co/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /reinhards.co/$1
RewriteCond %{HTTP_HOST} ^(www.)?reinhards.co$
RewriteRule ^(/)$ reinhards.co/index.php [L]
# END WordPress

但是,当有人输入时,我需要执行以下操作:

reinhards.co/xxxx

重定向到 reinhards.co/reinhards.co/xxxx ,但仍将 url 显示为 reinhards.co/xxxx

如果有人输入,我也很喜欢这个功能

reinhards.co/yyyy 重定向到 reinhards.co/reinhards.co/yyyy 因为这是一个有效的网页,但仍将网址显示为 reinhards.co/yyyy

【问题讨论】:

    标签: php wordpress apache .htaccess redirect


    【解决方案1】:
    RewriteCond %{REQUEST_URI} /test/
    RewriteCond %{QUERY_STRING} ^id=229
    RewriteRule ^.*$ /supermodel/? [R=301,L]
    

    类似的东西。

    【讨论】:

    • 谢谢,你介意把它分解一下,这样我就可以理解这里正在做什么?我还在学习 htaccess 字符和语法
    • 1 行说如果用户转到site.blah 并且路径是 /test/ 2 行说如果 GET 参数是 id=229 3 行说生成 url site.blah/supermodel/?id=229 并将用户重定向到它。跨度>
    • 还是我误解了,该查询搜索 I'd 并且仅在请求 uri 等于 229 时才重定向?
    • 是的,您只需删除第二行即可重定向所有来到 /test/ 路径的人
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多