2015-05-19 126 views
0

我的網站上的URL結構如下:http://www.mydomain.tld/index.php/pages/sitename。現在我想刪除index.php/pages,讓URL結構如http://www.mydomain.tld/sitename。此外,我想重新命名一些sitename的個人。使用mod_rewrite刪除index.php和文件夾名稱

我已經刪除了index.php,那沒問題。所以,目前我的.htacces-文件看起來像

DirectoryIndex index.php 
RewriteEngine on 

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico|pam) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php?$1 [QSA,L] 

RewriteCond %{HTTP_HOST} ^mydomain.tld\.de$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L] 

但是,如果我追加/pages到第一的RewriteCond或重寫規則,這是行不通的。 你有什麼想法嗎?

回答

0

有你的.htaccess這樣的:

DirectoryIndex index.php 

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^mydomain.tld\.de$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^((?!index\.php/pages/).*)$ index.php/pages/$1 [NC,L] 
+0

感謝您的幫助,但我認爲這是行不通的。我仍然使用www.mydomain.tld/sitename獲得404。我不能使用NE和第一個RewriteRule。如果我使用它,我無法通過http://mydomain.tld進入我的網站。 – pexmar

+0

你可以離開'NE'。也嘗試我更新的規則。 – anubhava

+0

不,不幸的是,這也行不通 – pexmar

相關問題