ayok Posted May 12, 2009 Share Posted May 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 12, 2009 Share Posted May 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/#findComment-832750 Share on other sites More sharing options...
ayok Posted May 13, 2009 Author Share Posted May 13, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/#findComment-833304 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 That works, but are there any restrictions on lang or can it be of any length? Quote Link to comment https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/#findComment-833486 Share on other sites More sharing options...
ayok Posted May 14, 2009 Author Share Posted May 14, 2009 I see... so How should I write the restrictions for only (EN/NL/DU) -> 2 capital letters? Quote Link to comment https://forums.phpfreaks.com/topic/157853-clean-url-with-many-variables/#findComment-834250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.