开发者

.htaccess mod_rewrite add "/" to the end of url

This is my .htaccess code:

RewriteBase /kajak/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^moduli/([^/]+)/(.*)$ moduli/$1/index.php/$2 [L]

Now / is appended to every URL. For example, http://127.0开发者_运维问答.0.1/moduli/novice becomes http://127.0.0.1/moduli/novice/.

How can I prevent getting / at the end?


While I do not know the answer to your question, I will note two oddities about your question and your code that may be related to the problem at hand.

  1. With the RewriteBase you have in your code, those rules should not even be being triggered.

  2. While I am new to regex myself, I look at ([^/]+) and am a little confused as to why you are capturing it. I know that ^ matches the START of the string, which would never be true since you already have another one at the real start of the string.

This being said, I would probably write the code as below:

RewriteBase /moduli/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ $1/index.php/$2 [L]

This would rewrite URLs as below:

http://www.website.com/moduli/novice/view
http://www.website.com/moduli/novice/index.php/view

Based on your block of code, this seems to be what you are trying to do. If it is not, then I am sorry.


I don't think that's related to your rewrite rule, (it does not match it).

The / is added because when you request http://example.com/xx/zz and the web server detects zz is a directory, it transforms it to http://example.com/xx/zz/ through a 301 redirect (the browser makes another request - check you apache logs).

Read about the trailing slash redirect thing here.

The, you must aks yourself, what do you want to happen when the url requested is http://127.0.0.1/moduli/novice/ (Do you want it to be be catched by your redirect or not? Currently it's not catched because of RewriteCond %{REQUEST_FILENAME} !-d)

BTW, I don't quite understand your RewriteBase /kajak/ line there - are you sure it's correct?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜