简体   繁体   English

htaccess重写如何工作

[英]how htaccess rewrite works

How the htaccesss code works and how they used to redirect the link why index.php is used?? htaccesss代码如何工作以及它们如何用于重定向链接,为什么使用index.php?

<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /XYZ/
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On # Enable the rewrite engine

RewriteBase /XYZ/ #The base url can also be called as root url

RewriteRule ^index.php$ - [L] #Content between ^ $ are rewritten [L] is a flag

RewriteCond %{REQUEST_FILENAME} !-f # Don't select files

RewriteCond %{REQUEST_FILENAME} !-d #Don't select directory

Check about flags in Apache docs https://httpd.apache.org/docs/current/rewrite/flags.html 检查Apache文档https://httpd.apache.org/docs/current/rewrite/flags.html中的标志

Have more question ask in comment. 还有更多问题要问。

Side note Use this if you have multiple conditions 旁注如果您有多种情况,请使用此选项

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM