Connecting Tech Pros Worldwide Forums | Help | Site Map

url rewriting

Member
 
Join Date: Jun 2008
Posts: 97
#1: Jan 30 '09
hi to all
i am facing strange problem hopefully due to my any basic mistake
when i use code in .htaccess like this
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^d-([A-Za-z0-9-]+)?$ page.php?abc=$1 [NC,L]
  2.  
then it will work properly but when i use "/" instead of "-" then page is unable to get effect of my css file

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^d/([A-Za-z0-9-]+)?$ page.php?abc=$1 [NC,L]
  2.  
what could be the problem

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#2: Jan 31 '09

re: url rewriting


Hi.

The / char is used in URLs to indicate a directory.

So, if you rewrite an URL that includes this char to point to a different level of the directory hierarchy, any relative URLs in the file are most likely going to become invalid.

To avoid this, make sure that all links and external resources use absolute paths.

An alternative solution would be to catch any CSS file in a RewriteRule and point it to the proper location, but that can cause other, cache related problems.
Newbie
 
Join Date: Feb 2009
Posts: 8
#3: Feb 22 '09

re: url rewriting


I have a similar question on the same matter. I'm wonder how I can use multiple RewriteRules for different files.. currently I am only able to Rewrite one and if I use any more they either dont work or will cause an error.. here is the code I'm using:

Expand|Select|Wrap|Line Numbers
  1. <IfModule mod_rewrite.c>
  2.   Options +FollowSymlinks
  3.   RewriteEngine on  
  4.   RewriteCond %{REQUEST_FILENAME} !-f
  5.   RewriteCond %{REQUEST_FILENAME} !-d
  6.   RewriteRule ^(.*)$ link.php?get=$1 [L,QSA]
  7. </IfModule>
  8.  
I'd like to add the code below for basic actions:

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?do=$1 [L,QSA]
  2.  
then i'd like to have this one

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?do=$1&search=$2&type=$3&page=$4 [L,QSA]
  2.  
which turns out like: /search/$2

If you could give me some help as well that would be great.. I'm starting to learn this stuff but I still dont get it.. :\

Thanks guys.
Newbie
 
Join Date: Mar 2009
Posts: 1
#4: Mar 6 '09

re: url rewriting


Hi All,
I am also looking for a solution of URL ReWriting. i am looking to convert the url like urlname/foldername to foldername.ulsername .

but when i convert it , it dosnt show the page. please help
Kelicula's Avatar
Expert
 
Join Date: Jul 2007
Posts: 169
#5: Apr 11 '09

re: url rewriting


Quote:

Originally Posted by DeadSilent View Post

I have a similar question on the same matter. I'm wonder how I can use multiple RewriteRules for different files.. currently I am only able to Rewrite one and if I use any more they either dont work or will cause an error.. here is the code I'm using:

Expand|Select|Wrap|Line Numbers
  1. <IfModule mod_rewrite.c>
  2.   Options +FollowSymlinks
  3.   RewriteEngine on  
  4.   RewriteCond %{REQUEST_FILENAME} !-f
  5.   RewriteCond %{REQUEST_FILENAME} !-d
  6.   RewriteRule ^(.*)$ link.php?get=$1 [L,QSA]
  7. </IfModule>
  8.  
I'd like to add the code below for basic actions:

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?do=$1 [L,QSA]
  2.  
then i'd like to have this one

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?do=$1&search=$2&type=$3&page=$4 [L,QSA]
  2.  
which turns out like: /search/$2

If you could give me some help as well that would be great.. I'm starting to learn this stuff but I still dont get it.. :\

Thanks guys.

You are searching the URI for the same match on each rewrite rule. So Apache doesn't know which one you wish to match.

This match is true if the url matches "any" character. One or more times from beginning to end of url.
RewriteRule ^(.*)$ index.php?do=$1 [L,QSA]

This one also matches the same criteria.
RewriteRule ^(.*)$ link.php?get=$1 [L,QSA]

How are you going to specify when to "do" or "get"?

Also, the capture only occurs once. So you have not populated $2, $3 etc...
The last rewrite rule will always fail.
RewriteRule ^(.*)$ index.php?do=$1&search=$2&type=$3&page=$4 [L,QSA]

Here's a good article.
Apache Mod_rewrite
Reply