0

I never want index.php to show up in my URL, even if the user inputs it. Is this possible?

This is variation whatever after several tries. I've come close a few times but this is where it's at for now.

RewriteEngine On  
RewriteBase /sub-dir/  
RewriteCond %{REQUEST_URI} index\.php$  //If URL ends in index.php
RewriteRule (.*)index\.php $1  //Somehow remove index.php from the url
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . index.php [L]  

Currently I have permalink set up where if the user enters domain.com/sub-dir/my-perma-lin/ it generates a string on the page based on my-perma-link to look like My Perma Link. What I'd like is if the user submits any URL ending in index.php it just removes that from the URL but leaves everything else as is.

domain.com/sub-dir/index.php --> domain.com/sub-dir/
domain.com/sub-dir/my-perma-link/index.php --> domain.com/sub-dir/my-perma-link

I've written quite a few rules in http://htaccess.madewithlove.be/ that work perfectly but when I upload it (to Dreamhost) nothing works.

This for example should work according to the the tester

RewriteEngine On  
RewriteBase /sub-dir/  
RewriteCond %{REQUEST_URI} \.php  //Not needed but thought it would/should help
RewriteRule (.*)(index\.php)+ $1 [L,R=301,NC]

But it just removes everything after /sub-dir/

I'm either missing something super obvious or it's not possible ...

4

1 回答 1

1

您需要在规则中添加一些标志:

RewriteEngine On  
RewriteBase /sub-dir/  
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(\?|\ )
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . index.php [L]  

您可以放弃RewriteCond %{REQUEST_URI} index\.php$条件,因为RewriteRule. 您需要$在正则表达式的末尾包含 a ,并包含L停止重写和R=301重定向的标志。

于 2012-10-18T06:26:31.007 回答