You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Eben Goodman <eb...@bakedbean.net> on 2003/11/18 03:24:29 UTC

[users@httpd] mod_rewrite syntax question

I have the following mod_rewrite directives in a .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php.*
RewriteRule ^(.+) - [L]
#RewriteCond %{REQUEST_URI} ^/(.*)$
#RewriteRule ^([A-Za-z0-9]+)/?$ index.php?request=$1 
[T=application/x-httpd-php,L]
RewriteRule ^(.+)/?$ index.php?request=$1 [T=application/x-httpd-php,L]

it works, the result is the ability to use a url like 
www.domain.com/value/value/ and have it be rewritten as 
www.domain.com/index.php?request=value/value

the problem is that I can't use a url like www.domain.com/value/value - 
without the trailing slash I get a 404 error.  If I take the 6th line:
RewriteRule ^(.+)/?$ index.php?request=$1 [T=application/x-httpd-php,L]
and remove the question mark like so:
RewriteRule ^(.+)/$ index.php?request=$1 [T=application/x-httpd-php,L]

I can use urls without trailing slashes, but then my style sheets and 
images don't resolve.  I'm still a bit of a novice with the mod_rewrite 
regex syntax, and am a bit baffled by this.  Any advice is appreciated.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite syntax question

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 17 Nov 2003, Eben Goodman wrote:

> thanks for the reply,
>
> so I tried this and it didn't work, is there another way to use the R flag?
>
> RewriteEngine on
> RewriteCond %{REQUEST_URI} ^/index\.php.*
> RewriteRule ^(.+) - [L]
> RewriteRule ^(.+)/$ index.php?request=$1 [T=application/x-httpd-php,R,L]
>
> thanks for your time,

I meant take the specific case where you need to add the trailing slash
and do a redirect for that.  Leave the other cases the same.  (It makes no
sense to change the content-type on a redirect.)

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite syntax question

Posted by Eben Goodman <eb...@bakedbean.net>.
thanks for the reply,

so I tried this and it didn't work, is there another way to use the R flag?

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php.*
RewriteRule ^(.+) - [L]
RewriteRule ^(.+)/$ index.php?request=$1 [T=application/x-httpd-php,R,L]

thanks for your time,

Eben



Joshua Slive wrote:

>On Mon, 17 Nov 2003, Eben Goodman wrote:
>  
>
>>the problem is that I can't use a url like www.domain.com/value/value -
>>without the trailing slash I get a 404 error.  If I take the 6th line:
>>RewriteRule ^(.+)/?$ index.php?request=$1 [T=application/x-httpd-php,L]
>>and remove the question mark like so:
>>RewriteRule ^(.+)/$ index.php?request=$1 [T=application/x-httpd-php,L]
>>
>>I can use urls without trailing slashes, but then my style sheets and
>>images don't resolve.  I'm still a bit of a novice with the mod_rewrite
>>regex syntax, and am a bit baffled by this.  Any advice is appreciated.
>>    
>>
>
>I don't precisely understand the details of your problem, but it appears
>the basics are: you want to be able to use a URL without a trailing slash,
>but you need the trailing slash to make relative references work.
>
>The standard solution to this is to do an external redirect ([R] flag to
>rewriterule) to send the client from the bad url to the good url.
>
>Joshua.
>
>---------------------------------------------------------------------
>The official User-To-User support forum of the Apache HTTP Server Project.
>See <URL:http://httpd.apache.org/userslist.html> for more info.
>To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>For additional commands, e-mail: users-help@httpd.apache.org
>
>
>
>  
>


Re: [users@httpd] mod_rewrite syntax question

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 17 Nov 2003, Eben Goodman wrote:
> the problem is that I can't use a url like www.domain.com/value/value -
> without the trailing slash I get a 404 error.  If I take the 6th line:
> RewriteRule ^(.+)/?$ index.php?request=$1 [T=application/x-httpd-php,L]
> and remove the question mark like so:
> RewriteRule ^(.+)/$ index.php?request=$1 [T=application/x-httpd-php,L]
>
> I can use urls without trailing slashes, but then my style sheets and
> images don't resolve.  I'm still a bit of a novice with the mod_rewrite
> regex syntax, and am a bit baffled by this.  Any advice is appreciated.

I don't precisely understand the details of your problem, but it appears
the basics are: you want to be able to use a URL without a trailing slash,
but you need the trailing slash to make relative references work.

The standard solution to this is to do an external redirect ([R] flag to
rewriterule) to send the client from the bad url to the good url.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org