Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite rewriterule 404 error

         

heals1ic

10:13 am on Nov 11, 2010 (gmt 0)

10+ Year Member



I am trying to implement a mod rewrite using the following in my .htaccess file in the root folder of my website -

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteRule ^([^/]+)/([^/]+)/property-details/([^/]+)/$ property-details.php?uniqueID=$1&retpg=$2


the URL I am trying to rewrite is -

http://website.com/106320257/carousel/property-details/seo-friendly-text/


I keep getting a 404 page error

Any ideas why?

sublime1

8:22 pm on Nov 12, 2010 (gmt 0)

10+ Year Member



Hi --

The regular expression looks correct.

You might need a / at the beginning of the target on the rewrite? If property-details.php is in the web root, then that's probably the issue.


# Add a / before the target of the rewrite
RewriteRule ^([^/]+)/([^/]+)/property-details/([^/]+)/$ /property-details.php?uniqueID=$1&retpg=$2


You may want to save yourself some future aggravation by adding an [L] flag so that Rewrite knows it doesn't need to keep processing further rewrites ... not that you have any for now. Also, I believe the last capture group is unused so you could adjust, like


# Add a / before the target of the rewrite, remove last capture group, add L flag
RewriteRule ^([^/]+)/([^/]+)/property-details/[^/]+/$ /property-details.php?uniqueID=$1&retpg=$2 [L]


If that doesn't work, you should also be able to test with an ugly URL, so


http://website.com/property-details.php?uniqueID=106320257&retpg=carousel


and it should work (it will not get picked up by the RewriteRule because it doesn't match the pattern so just get passed through). If it doesn't, then the problem is not with the rewrite rule.

Tom

heals1ic

12:31 am on Nov 13, 2010 (gmt 0)

10+ Year Member



Thanks for your reply I have weeded out the issue to being one of my directives in the virtual host config in httpd.conf -

old config -

<VirtualHost [ipaddress]:80>
DocumentRoot /var/www/html/website
ServerName website.com.au
ServerAlias website.com.au website
ServerAdmin root@website.com.au
DirectoryIndex index.php index.html index.htm index.shtml
<Directory "/var/www/html/website">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteLog "/var/www/html/website/rewrite.log"
RewriteLogLevel 10
</IfModule>
HostNameLookups on
</VirtualHost>


AllowOverride
cannot be
none


or there will be now rewrite

jdMorgan

1:43 am on Nov 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The RewriteCond and RewriteRule directives both require AllowOverride FileInfo at minimum, as documented in the mod_rewrite documentation. In addition, the Options directive in your .htaccess file will cause a server error unless you also set AllowOverride Options.

But since you have already set Options FollowSymLinks in your config file, the redundant Options directive in your .htaccess file isn't really needed.

Jim