Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic htaccess code not working

Tags:

.htaccess

This is really frustrating for me that I have been trying to get this very basic htaccess rewrite working from hours long but couldn't do it.

I have tried following.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /funshoppie/

############ Details page ################
RewriteCond %{THE_REQUEST} Deal\-details\.php\?title\=([A-Za-z0-9-]+)&id=(\d+) [NC]
RewriteRule ^%1%2? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^Deals/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ Deal-details.php?title=$1&id=$2 [NC,QSA,L]

can anyone tell me what wrong i am doing?

url i am trying to rewrite

http://localhost/funshoppie/Deal-details.php?title=Styling%20Tools%20-%2020%%20off&id=7

what i wish after success

http://localhost/funshoppie/Deals/Styling-Tools-20%-off/7

I have checked error logs, httpconf & ensured uncommented rewrite_module. Don't know whats causing this error.

like image 261
techworld Avatar asked Jul 30 '16 14:07

techworld


People also ask

Why is my htaccess not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.

How do I know if htaccess is working?

In your browser, open /test , with the correct domain name. So, it should look like http://localhost/test or http://example.org/test . If you see the following, it works!

How long does it take for .htaccess to update?

htaccess files follow the same syntax as the main configuration files. Since . htaccess files are read on every request, changes made in these files take immediate effect.


1 Answers

I cannot try this at the moment but, your regular expression is not fitting the URL:

Deal-details.php?title=Styling%20Tools%20-%2020%%20off&id=7

Based on en- and decoding this could be the following two string:

  • Deal-details.php?title=Styling%20Tools%20-%2020%%20off&id=7
  • Deal-details.php?title=Styling Tools - 20% off&id=7

In none of the cases matches your expression:

[..] Deal-details.php\?title\=([A-Za-z0-9-]+)&id=(\d+)[..]

You are missing represented characters from your expressions like:

  • "%"
  • " " (space)

Try the following expression:

Deal\-details\.php\?title\=(.+)&id=(\d+)

This will match any characterafter title. Otherwise I see no problem there.

like image 187
Hash Avatar answered Sep 30 '22 13:09

Hash