relative path doesn't work after adding a rewr

2019-08-03 09:32发布

I have an index page placed in /forum/section1/. I have a rule to automatically redirect to the index page when I browse exampledomain.com/forum/section1/. Sometimes when I forgot the trailing slash, it keeps loading and never goes to the index page. I have added a rule to append a trailing slash to every request:

RewriteEngine on
#From http://enarion.net/web/htaccess/trailing-slash/ 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
# Don't apply to images/css/js/ajax files
RewriteCond %{REQUEST_URI} !^.*\.(jpg|jpe?g|ico|css|js|gif|png|php)$ [NC]
RewriteRule ^(.*)$ http://exampledomain.com/$1/ [L,R=301] 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^.*\.(jpg|jpe?g|ico|css|js|gif|png)$ [NC]

#Remove php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]

The rules are working, but all of the relative paths become invalid. For example, I have a form on the index page:

       `<form action='index' method='POST'></form>`

Instead of accessing exampledomain/forum/section1/index/, it would redirect to exampledomain/forum/section1/index/index. I know changing relative paths to absolute paths would fix the problem, but is there a way to fix that with the rewrite rules?

0条回答
登录 后发表回答