URL重写代码无法在我的.htaccess上运行

问题描述 投票:0回答:3

我的原始网址

http://www.mcoh.co.in/blog-single?category=Blog&id=Janurary%202018%20Product%20training%20Scores

期待:

http://www.mcoh.co.in/mcohBlog/Janurary%202018%20Product%20training%20Scores

但是我收到了与原始相同的网址。

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^mcoh([^/]*)/([^/]*)\$ /blog-single?category=$1&id=$2 [L]
php .htaccess url url-rewriting url-rewrite-module
3个回答
0
投票

你对这一行的问题:

RewriteRule ^mcoh([^/]*)/([^/]*)\.php$ /blog-single?category=$1&id=$2 [L]

替换为:

RewriteRule ^mcoh([^/]*)/([^/]*)$ /blog-single?category=$1&id=$2 [L]

之前的规则已删除该扩展程序。

此外,您的代码应如下所示:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^mcoh([^/]*)/([^/]*)$ /blog-single?category=$1&id=$2 [L,NE]

0
投票
RewriteEngine on
RewriteRule ^/?mcohBlog/([^/d]+)/?$ blog-single.php?category=Blog&id=$1 [L,QSA]

你能试试吗?只需在代码末尾添加此重写符。并删除您的最后一行代码


编辑

你的代码组织也是非常错误的。这就是为什么它不按预期工作的原因

Options +FollowSymLinks -MultiViews     
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^/?mcohBlog/([^/d]+)/?$ blog-single.php?category=Blog&id=$1 [L,QSA]

这应该是你的最后一个代码


0
投票

重定向/重写

http://www.mcoh.co.in/blog-single?category=Blog&id=Janurary%202018%20Product%20training%20Score

http://www.mcoh.co.in/mcohBlog/Janurary%202018%20Product%20training%20Scores

将以下内容放在htaccess文件的顶部

RewriteEngine on

#To externally redirect /blog-single?category=foo&id=bar to /mochBlog/bar
RewriteCond %{QUERY_STRING} ^category=([^&]+)&id=(.+)$ [NC]
RewriteRule ^.*$ /mochBlog/%2? [R,L]
#To internally redirect /mochBlog/bar to /blog-single?category=foo&id=bar
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^mochBlog/(.+)$ /blog-single?category=blog&id=$1 [L]
© www.soinside.com 2019 - 2024. All rights reserved.