Apache 我如何设置htaccess来执行此操作?
我正在尝试设置htaccess文件以执行以下重定向: http://www.mysite.com/about应链接到http://www.mysite.com/content/pages/about.php http://www.mysite.com/login应链接到http://www.mysite.com/content/pages/login.php http://www.mysite.com/prices应链接到http://www.mysite.com/content/pages/prices.phpApache 我如何设置htaccess来执行此操作?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我正在尝试设置htaccess文件以执行以下重定向: http://www.mysite.com/about应链接到http://www.mysite.com/content/pages/about.php http://www.mysite.com/login应链接到http://www.mysite.com/content/pages/login.php http://www.mysite.com/prices应链接到http://www.mysite.com/content/pages/p
感谢仅重定向您提供的URL,您可以使用此类规则(您可以将其他页面添加到您需要的URL列表中): 要将所有不存在的页面重定向到
/content/pages/PAGE\u NAME.php
,可以使用以下规则:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# do not do anything for already existing files (like images/css/js etc)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# redirect everything else
RewriteCond %{REQUEST_URI} !^/content/pages/
RewriteRule ^(.+)$ /content/pages/$1.php [L]
注意事项:
您需要将这些规则放入网站根文件夹中的.htaccess中。如果放在其他地方,可能需要一些小的调整
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# do not do anything for already existing files (like images/css/js etc)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# redirect everything else
RewriteCond %{REQUEST_URI} !^/content/pages/
RewriteRule ^(.+)$ /content/pages/$1.php [L]