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