문제

I want to rewrite my URLs which are based upon directories I have My directories look like this:

index.php
galleries
   -Party Weekend
       -2014
          -Bunchofimages.png
   -Other pics
       -Pictures.png

And the urls look like:

example.com/?f=/Party%20Weekend/2014

And I was looking for something like

example.com/Party-Weekend/2014

(Can be a dash or a + sign, doesn't really matter)

(Using .htaccess seems like the best option but I have no experience with .htaccess at all)

Also do I need to customize every single folder in the rewrite engine or can this be done dynamicly? (So I don't need to make a new rule for every folder I create)

I tried this but doesn't rewrite anything at all

RewriteEngine On 
RewriteRule ^([^/]*)/$ /?f=$1 [L]

Am I doing something wrong here?

도움이 되었습니까?

해결책

Try something like:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+\?f=([^\ &]+)
RewriteRule ^ /%1? [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/galleries%{REQUEST_URI} -d
RewriteRule ^(.*)$ /?f=$1 [L]

There may be some encoding issues related to the spaces in your folder names, so you may either need some combination of the NE or B flags in side the brackets.

다른 팁

Using .htacces is the best and only way you don't have to customize all folders you do it all dynamically please go to this page for more details its easy URL Rewriting for Beginners : http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top