Php 使用.htaccess重写url以删除不需要的单词
我需要重写url,其中url为:Php 使用.htaccess重写url以删除不需要的单词,php,regex,wordpress,.htaccess,redirect,Php,Regex,Wordpress,.htaccess,Redirect,我需要重写url,其中url为: http://www.domainname.co.uk/blog/gallery/gallery2 --> URL1 哪一个需要 http://www.domainname.co.uk/gallery/gallery2 ---> URL2 其中是安装了wordpress的目录。 现在,当我输入URL2时,它应该显示URL1的内容。 可能吗?我只需要删除单词blog -----------我的.htaccess--------- 重新启动发
http://www.domainname.co.uk/blog/gallery/gallery2 --> URL1
哪一个需要
http://www.domainname.co.uk/gallery/gallery2 ---> URL2
其中是安装了wordpress的目录。
现在,当我输入URL2时,它应该显示URL1的内容。
可能吗?我只需要删除单词blog
-----------我的.htaccess---------
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
重写规则^(画廊/+)$/blog/$1[L,北卡罗来纳州]
编辑:如果您在htaccess所在的根文件夹中使用index.php,则可以使用如下重写规则
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
RewriteRule ^gallery$ http://www.domainname.co.uk/blog/gallery/1$ [L,P]
RewriteRule . /index.php [L]
</IfModule>
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(画廊/+)$/blog/$1[L,北卡罗来纳州]
重写规则^gallery$http://www.domainname.co.uk/blog/gallery/1$[L,P]
重写规则/index.php[L]
考虑使用重定向插件:Hi anil。。感谢您的回复,但它不起作用:(wordpress中的.htaccess似乎有问题?wordpress中的问题是什么?您可以指定以便我可以详细帮助您吗?如果您再次测试,上htaccess规则也适用于wordpress(如果您从上面复制了我的旧htaccess代码,我将使用新的htaccess编辑它)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
RewriteRule ^gallery$ http://www.domainname.co.uk/blog/gallery/1$ [L,P]
RewriteRule . /index.php [L]
</IfModule>