How to change URL? htaccess

一个人想着一个人 提交于 2020-01-21 21:49:11

问题


What I have

newsy/czytaj/items/odbierz-250zl-na-reklame.html

This is what I would have

newsy/odbierz-250zl-na-reklame.html

How to do this with mod-rewrite? I don't understand RewriteRule.

My .htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} (ftp|https?):|/etc/ [NC,OR]
RewriteCond %{QUERY_STRING} (ftp|https?):|/etc/ [NC]
RewriteRule .* - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*\.html$ index.php [L]

回答1:


RewriteEngine on
RewriteRule ^newsy/([^\./]+)\.html /newsy/czytaj/items/$1.html [L]

This will rewrite anything that starts with newsy and add a /czytaj/items between it and the html file.




回答2:


In principle you just create a corresponding rewrite rule:

RewriteRule ^newsy/czytaj/items/(.+) /newsy/$1 [L]

It is crucial not to omit [L]flag. Otherwise your rewrite engine may get stuck in an endless loop. Also in the beginning of the .htaccessfile remember to enable mod_rewrite with:

RewriteEngine On

For more help on mod_rewrite, I recommend checking out mod_rewrite-cheatsheet. For an exhaustive URl Rewriting Guide see a corresponding page from Apache 2.0 Documentation.



来源:https://stackoverflow.com/questions/8301249/how-to-change-url-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!