PHP - problem with Semantic URL Query String - .htaccess

I try to send query string with Semantic URL.
.htaccess:
RewriteEngine On
RewriteRule ^product/([0-9a-zA-Z]+) product.php?link=$1 [NC,L]
when i try 'localhost/product' it work and direct me to product.php but when i try to send query string :
localhost/product/Acer-s7
It won't work.

Thanks to #CBroe comment. its working now i should disable MultiViews by adding this code to my .htaccess:
Options +FollowSymLinks -MultiViews -Indexes

Related

Get variable with htaccess

I have this in my htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^associato/([0-9]+)/(.*)$ associato.php?idassociato=$1 [QSA,L]
But when I try to go at:
http://www.mydomain.it/associato/1/a
the page associato.php is called correcty, but
$idassociato = $_GET['idassociato'];
echo $idassociato;
return nothing...did I do something wrong?
You need to disable multiviews on your server , try :
Options -Multiviews
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^associato/([0-9]+)/(.*)$ associato.php?idassociato=$1 [QSA,L]
If you are using Debian, please disable the MultiViews option.
See https://serverfault.com/questions/83380/apache-extensionless-urls-get-an-automatic-php-extension
The reason why you got this is that Apache will try /associato.php when you accessing /associato/1/a, thus dividing /1/a as pathinfo. But how it fails with 404 is far than I know.

Rewriteurl Category Id

I want to remove my subcategory id's and redirect to new url with rewriteurl. I have lots of url like that
www.abc.com/category/(subcategoryid)-subcategory/(articleid)-article.html
Example;
www.abc.com/category/12-subcategoryA/1054-article.html
www.abc.com/category/23-subcategoryB/1072-another-article.html
vs.
to
www.abc.com/category/subcategoryA/1054-article.html
www.abc.com/category/subcategoryB/1072-another-article.html
Can you help me please.
Regards
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(category)/[0-9]+-([^/]+/[^.]+\.html)$ /$1/$2 [L,NC,R=302]

.htaccess URL rewrite issue. Works on online tester, but not on the hosting server

The URL can be in the format of either:
http://www.example.com/subdomain/123456 or http://www.example.com/123456
I need to rewrite it to:
http://www.example.com/content_pages.php?page=about_us&refferal=123456
I'm using:
RewriteRule ^(/?\w*/?)(\d{4,10})$ $1content_pages.php?page=about_us&refferal=$2 [NC,L]
It works on then online RegEx tester. But gives 404 error on the actual site. Pleaes help.
Try this code instead:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+/)?(\d{4,10})/?$ /$1content_pages.php?page=about_us&refferal=$2 [L,QSA]

Simple Htaccess redirect not working

For some reason this is not working...
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url
I have no idea why... If I replace the URL being redirected with another non-existent one (/helloworld) it redirects fine to the new url..
Is it catching on something? I tried escaping (/modules.php\?name=News&file=article&sid=179) but it didn't make any difference, still just 404s.
any help is appreciated!
You can't match against the query string in the Redirect directive, you'll have to use mod_rewrite and the %{QUERY_STRING} variable. Try this:
RewriteCond %{QUERY_STRING} name=News&file=article&sid=179
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
# There is a ? here to prevent query strings appending -----^

.HTACCESS Rewriting Issue

Can any check given code of .htaccess file and let me know what's wrong with it and why it's not working?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^itinerary/([a-zA-Z0-9_-]+)/([0-9]+)\$ itinerary-details.php?tId=$2
I want to rewrite url as below:
www.domain.com/itinerary-details.php?tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour
and
www.domain.com/itinerary-details.php?page=1&tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour/1
Please help me in doing this.
Thanks
Seems that you have the two sections in your regex reversed. This should work for both your cases:
^itinerary/([0-9]+)/([a-zA-Z0-9_-]+)/?(.*) itinerary-details.php?tId=$1&tName=$2&page=$3
I also just noticed that you were escaping the $ which would also cause problems.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^itinerary/([^/]+)/([^/]+)/?$ /itinerary-details.php?tId=$1&tName=$2 [L,QSA,NC]
RewriteRule ^itinerary/([^/]+)/([^/]+)/([^/]+)/?$ /itinerary-details.php?page=$3&tId=$1&tName=$2 [L,QSA,NC]

Resources