开发者

Mod Rewrite problem

开发者 https://www.devze.com 2022-12-08 10:01 出处:网络
.htacces Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1 [L]

.htacces

Options +FollowSymLinks
RewriteEngine On

RewriteBase / 
RewriteRule ^([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L]


RewriteRule ^([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3 [R=301,L]
RewriteRule ^([a-zA-开发者_开发技巧Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3/$4 [R=301,L]

There is folder sinj.com.hr/administracija and when I try to access http://localhost/sinj.com.hr/administracija I am redirected to http://localhost/sinj.com.hr/administracija?var1=administracija What I would like is when user enters http://localhost/sinj.com.hr/administracija that he is redirected to http://localhost/sinj.com.hr/administracija/index.php. I tried to do this with header("Location:... ") but it always redirects me to http://localhost/sinj.com.hr/administracija?var1=administracija. If folder administracija is renamed then header() function works. Any ideas how to solve this?

Thanks, Ile


Try this rule to test if the request can be mapped to a directory that contains an index.php file:

RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^ %{REQUEST_URI}/index.php

Additionally you can use this single rule to redirect any requests with a URL path that ends with a slash the one without:

RewriteRule ^(.+)/$ sinj.com.hr/$1 [R=301,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号