Apache 使用mod_rewrite更改url路径
是否可以使URL中的文件夹透明,如以下示例所示: example.com/test/ 改为 example.com/ 使用mod_重写Apache 使用mod_rewrite更改url路径,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,是否可以使URL中的文件夹透明,如以下示例所示: example.com/test/ 改为 example.com/ 使用mod_重写 我喜欢组织文件夹,但我想要一个干净的url。您可以通过mod_rewrite在根文件夹的.htaccess文件中添加类似的内容来实现这一点: RewriteEngine on # the first condition is for avoiding an infinite loop RewriteCond %{REQUEST_URI} !^/test/.*
我喜欢组织文件夹,但我想要一个干净的url。您可以通过mod_rewrite在根文件夹的
.htaccess
文件中添加类似的内容来实现这一点:
RewriteEngine on
# the first condition is for avoiding an infinite loop
RewriteCond %{REQUEST_URI} !^/test/.*
RewriteRule ^(.*)$ /test/$1
这将重定向到从/
请求的所有页面/文件
如果只想重定向某些文件,请使用更具体的规则:
或者,如果要使用不同的文件夹:
RewriteEngine on
# the condition is for avoiding an infinite loop
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteCond %{REQUEST_URI} !^/docs/.*
# redirecting only images files and files that start with "doc"
RewriteRule ^(.*\.(jpg|png|gif))$ images/$1 [L]
RewriteRule ^(doc.*)$ docs/$1 [L]
您可以通过mod_rewrite在根文件夹的
.htaccess
文件中添加类似的内容来实现这一点:
RewriteEngine on
# the first condition is for avoiding an infinite loop
RewriteCond %{REQUEST_URI} !^/test/.*
RewriteRule ^(.*)$ /test/$1
这将重定向到从/
请求的所有页面/文件
如果只想重定向某些文件,请使用更具体的规则:
或者,如果要使用不同的文件夹:
RewriteEngine on
# the condition is for avoiding an infinite loop
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteCond %{REQUEST_URI} !^/docs/.*
# redirecting only images files and files that start with "doc"
RewriteRule ^(.*\.(jpg|png|gif))$ images/$1 [L]
RewriteRule ^(doc.*)$ docs/$1 [L]
如何更改,使用重定向或内部重写?你能描述一下当用户输入一个URL和另一个URL时会发生什么吗?你的意思是将
root\u文件夹/test/page.html
这样的文件作为example.com/page.html
提供吗?@Pekka internal rewrite最好@Alberto exactlychange how,使用重定向或内部重写?你能描述一下当用户输入一个URL和另一个URL时会发生什么吗?你是说像root\u folder/test/page.html
这样的文件作为example.com/page.html