[英]Apache mod_rewrite rule for sub directory
我正在嘗試設置一個重寫規則,以便將localhost / test / {this}之后的任何內容轉發到localhost / test / index.php?{here}
我可以訪問服務器,當前配置如下所示:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/www/test/>
AllowOverride All
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?$1
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
但是此刻,當訪問localhost / test / something時,它沒有顯示/localhost/test/index.php?而是顯示localhost / index.php,所以它被重寫到了錯誤的位置。 謝謝
在/ var / www / test中創建.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
已解決。.我發現,每當我包含AllowOverride All時,它將全部重定向到/index.php,然后發現我從較早的測試中將.htaccess文件留在那里,這使事情變得混亂。 已刪除,更新了我的規則,現在可以使用了。 感謝幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.