Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help

         

ghazanchyan

10:45 am on Jul 21, 2006 (gmt 0)

10+ Year Member



I tried to edit the example listed in the forum for my needs and it's not working.
I have the following URL "/?p=about" and I want to get "/about/"

RewriteRule ^/([^/]+)/?$ /?p=$1 [L]
This row gives the result "//about/" and when I try to delete the slash after ^ I get 500 Internal Error

Here is the full code of .htaccess
----
# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^/([^/]+)/?$ /?p=$1 [L]
#
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?p=([^\ ]+)\ HTTP/
RewriteRule ^$ [mysite.com...] [R=301,L]
----

Please help.

jdMorgan

1:48 pm on Jul 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's probably because the rule will cause an 'infinite' rewriting loop if the substitution URL matches the RewriteRule pattern - Check your server error log file to verify this.

In this case, you should rewrite to a fully-defined URL-path, not to "/" followed by "?p=$1"

And if the script path matches the rule pattern, then you'll need to exclude the script path from the rewrite to prevent the loop.

In other words:


RewriteCond %{REQUEST_URI} !^/my-script\.php$
RewriteRule ^/([^/]+)/?$ /my-script.php?p=$1 [L]

Otherwise, DirectoryIndex will get involved in translating "/" to a filepath, and will complicate matters.

Jim