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
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.

Link to comment
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.

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.