Jump to content

Clean URL with many variables


ayok

Recommended Posts

Hi,

 

I don't completely understand about apache, but i need to know about creating clean url for my php site. So far, for a simple website with simple navigation and/or modules I can make static url from simple php url, like index.php?page=home into /home.html. However, when I have 3 or more variables, it becomes more puzzle for me.

 

For some reasons i need to throw variables like this, ?id=1&menu=1&page=news and this make me headache ??? Some even more variables. So far, I've tried and I got this kind of static url, "1-1_news.html", which is fine for me, but then to have more variables like &lang=EN would be another headache for me ??? My question now is how to make even clearer than 1-1_news.html? Like news.html? I've tried 1/1/news.html but then the images are not shown because the links miss the path.

 

This is one of the lines in my .htaccess:

RewriteRule ^([0-9_-]+)-([0-9_-]+)_([0-9_-]+)_([a-z_-]+).html$    	index.php?pageID=$1&menu=$2&id=$3&name=$4

 

Thanks,

ayok

Link to comment
https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/
Share on other sites

For URL like : http://www.mysite.com/2-3_1_abc.html

To be internally rewritten for : http://www.mysite.com/index.php?pageID=2&menu=3&id=1&name=abc

 

This work :

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)-([0-9]+)_([0-9]+)_([a-z]+).html$ index.php?pageID=$1&menu=$2&id=$3&name=$4 [NC,L]
</IfModule>

 

The error was you can't use these characters -_ in both the regular expression and as separator or it won't know where to split the string.

For URL like : http://www.mysite.com/2-3_1_abc.html

To be internally rewritten for : http://www.mysite.com/index.php?pageID=2&menu=3&id=1&name=abc

 

This work :

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)-([0-9]+)_([0-9]+)_([a-z]+).html$ index.php?pageID=$1&menu=$2&id=$3&name=$4 [NC,L]
</IfModule>

 

The error was you can't use these characters -_ in both the regular expression and as separator or it won't know where to split the string.

 

Hi, Thanks theonlydrayk. But how if there come more like: http://www.mysite.com/index.php?pageID=2&menu=3&id=1&name=abc&lang=EN?

Should it be: RewriteRule ^([0-9]+)-([0-9]+)_([0-9]+)_([a-z]+)_([a-z]+).html$ index.php?pageID=$1&menu=$2&id=$3&name=$4&lang=$5 [NC,L]?

 

ayok

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.