Php 重定向.htaccess文件中的绝对路径
我有一个网站,以前页面的URL类似于:Php 重定向.htaccess文件中的绝对路径,php,.htaccess,redirect,Php,.htaccess,Redirect,我有一个网站,以前页面的URL类似于: 请注意,即使这些URL是.php文件,也没有扩展名。这是一个位于域根目录中的Wordpress站点。wordpress站点现在已经被移动到一个文件夹中,但我想设置一个从所有以前的URL重定向到新URL的重定向(出于SEO原因) 到目前为止,我找到了一个暂时的解决办法,这远远不够完美。我所做的是将其放入.htaccess文件中(以删除PHP扩展名): 然后,我创建了不同的文件,这些文件的名称与前面的URL相同(扩展名为.php,由于我的.htacc
<?php header('Location: THE_NEW_URL'); ?>
你不必是爱因斯坦就能知道,这是我的.htaccess文件,它是在wolfs中提出的。但是我该怎么办呢?有没有办法制作我的.htaccess文件,这样我就可以按照以下方式做一些事情:
Redirect from SPECIFIC_URL to A_NEW_SPECIFIC_URL
在我的域名上,它不会破坏所有的URL。我喜欢在我的文件上有扩展名。我只需要对这15个已经被移动的旧URL进行修复(没有扩展名)
我讨厌.htaccess文件,在任何地方都找不到任何教程。糟透了!我不知道怎样才能做得更好。我一直在实施我不了解的解决方案 我相信这会满足您的需求:
<IfModule mod_rewrite.c>
# enable URI rewrite
RewriteEngine on
# set virtual root
RewriteBase /
# if request is for an actual file or directory on disk,
# then do not continue with rewrite engine
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# setup rewrite table
RewriteRule ^page1$ page1.php [R=302,L]
RewriteRule ^page2$ page2.php [R=302,L]
RewriteRule ^page3$ page3.php [R=302,L]
</IfModule>
如果只有15个旧文件,一个简单的解决方案是对这15个文件进行硬编码
RewriteEngine on
RewriteRule ^/?oldfile1$ /new1/path1/file1.php [R,L]
RewriteRule ^/?oldfile2$ /new2/path2/file2.php [R,L]
RewriteRule ^/?oldfile3$ /new3/path3/file3.php [R,L]
...
+1代表
RewriteCond%{REQUEST_FILENAME}-f
,但不要在RewriteRule substitution.oops中转义。
——好的调用;编辑并删除了不必要的转义。看起来也可以。内森跑得更快,这和他的方法是一致的。不过谢谢你。
Redirect from SPECIFIC_URL to A_NEW_SPECIFIC_URL
<IfModule mod_rewrite.c>
# enable URI rewrite
RewriteEngine on
# set virtual root
RewriteBase /
# if request is for an actual file or directory on disk,
# then do not continue with rewrite engine
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# setup rewrite table
RewriteRule ^page1$ page1.php [R=302,L]
RewriteRule ^page2$ page2.php [R=302,L]
RewriteRule ^page3$ page3.php [R=302,L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteEngine on
RewriteRule ^/?oldfile1$ /new1/path1/file1.php [R,L]
RewriteRule ^/?oldfile2$ /new2/path2/file2.php [R,L]
RewriteRule ^/?oldfile3$ /new3/path3/file3.php [R,L]
...