如果你對網站的DocumentRoot爲/var/www/apps/
,那麼我想的網址是http://www.example.com/testapp1/ajax
而不是http://www.example.com/apps/testapp1/ajax
。如果是這樣 - 那麼您需要從這些規則中刪除apps/
部分。
這些規則需要放入您的.htaccess到網站根文件夾中。
如果您已經有一些規則,那麼這些新規則需要放置在正確的位置規則的順序很重要。
如果您還沒有此類功能,則可能需要在此處添加RewriteEngine On
行。
此規則將重寫/apps/testapp1/ajax
成/apps/testapp1/index.php
,沒有其它URL將會受到影響:
RewriteRule ^apps/testapp1/ajax$ /apps/testapp1/index.php [NC,QSA,L]
此規則將重寫與/ajax
端插入/index.php
(例如/apps/testapp1/ajax
=>/apps/testapp1/index.php
以及所有URL /apps/testapp2/ajax
=>/apps/testapp2/index.php
):
RewriteRule ^(.+)/ajax$ /$1/index.php [NC,QSA,L]
UPDATE:
這種 「萬能」 的規則將改寫/apps/testapp1/xxx
到/apps/testapp1/index.php
以及/apps/testapp2/something
=>/apps/testapp2/index.php
:
RewriteRule ^(.+)/([^/\.]+)$ /$1/index.php [NC,QSA,L]
感謝您的幫助。你能告訴我一種爲/ testapp1/xxx之類的所有URL創建通用正則表達式的方法嗎?我試過 RewriteRule ^(。+)/(。+)$ /$1/index.php [NC,QSA,L]沒有成功。 –
@Dapper Dan我用「通用」規則更新了我的答案,該規則適用於該類型的URL。 – LazyOne
感謝隊友,您救了我的命! :) –