What i'm trying to do is format my product urls like:
site.com/id-product-name/
Using my .htaccess i have this so far:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)-[^/]+\.html$ /service.php?serviceId=$1 [QSA,L]
This appends ".html" to the end of every product, which works great, but i would prefer a trailing slash at the end like shown above i tried:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)-[^/]+\/$ /service.php?serviceId=$1 [QSA,L]
But this doesn't work, i'm probably missing something small, any help would be appreciated!
Related
I have a strange problem where my SEF URLs just wont work for the word 'drills' I have just got around the issue by using a different word but Id like to know why this doesn't work.
This is my entire htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([0-9])/?$ /index.php?page=$1 [QSA,NC,L]
This works perfectly and redirects domain.com/page/1 to the correct domain.com/index.php?page=1
However, if I change the htaccess file to this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^drills/([0-9])/?$ /index.php?drill=$1 [QSA,NC,L]
I just get a url not found error.
To find out where it was going wrong I edited the htaccess 1 letter at a time so page became drills and it all worked correctly until I changed the initial letter. So this works:
RewriteRule ^prills/([0-9])/?$ /index.php?drill=$1 [QSA,NC,L]
but this is a URL not found:
RewriteRule ^drills/([0-9])/?$ /index.php?drill=$1 [QSA,NC,L]
Is there something special about the word 'drills' that means I can't use it for SEF URLs?
To fix it I've just used training-drills instead but it's bugging me that I couldn't get it to work with just the word 'drills'
This is my simple htaccess code:
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L]
My code is working fine for the followings:
mydomain/books/math
mydomain/books/english
mydomain/books/physics.applied
as
library/search.php?zig=math
library/search.php?zig=english
library/search.php?zig=physics.applied
But my code is not working only for
mydomain/books/
it is acting as
library/search.php?zig=index.php
There is no subject named index.php. I want to remove this index.php. My search function should not work for mydomain/books/
You can add a RewriteCond to ignore all files and directories from rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L,QSA]
I have this problem, I'm using my url like this:
If somebody is coming to the website from a referral the have something like https://myweb.site/UERHF723R so my htaccess have this:
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?ref=$1 [L,QSA]
but how I can send somebody to https://myweb.site/foldername without send them to index.php as a variable.
I think I can use something like this:
RewriteCond %{REQUEST_URI} foldername
RewriteRule .* /foldername/index.php
But I don't want to to this for every new folder, any suggestions?
You can use:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?ref=$1 [L,QSA]
In this way, you only rewrite urls that are not directories (-d) or files (-f)
The second line is therefore not mandatory in your case.
This my .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^products/([^/\.]+)/?$ /product.php?$1
RewriteRule ^category/([^/\.]+)/?$ /category.php?cat=$1&page=$2 [QSA,L]
the link i put into the browser is site.com/category/batteries/1/ where batteries is category and 1 would be the page. However, my site only gets the category (so site.com/category/batteries/ works, but site.com/category/batteries/1/ returns a 404.)
category.php gets the value being passed in cat, but not the value in page. I keep reading on this, but just can't understand where I'm going wrong.
You're missing a capturing group so $2 is never set. Try:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^products/(.*+)/?$ product.php?$1
RewriteRule ^category/(.*+)/(\d+)/?$ category.php?cat=$1&page=$2 [QSA,L]
Changing the regex worked. Just getting the text inbetween slashes instead of trying to find the digit gave me the desired result.
RewriteRule ^category/([^/]+)/([^/]+)/? /category.php?cat=$1&page=$2 [QSA,L]
htaccess :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
from dis line it will not work
RewriteRule ^blog/([a-zA-Z]+)/$ blog.php?cat=$2
My url http://localhost/Seo/blog.php?cat=SEO
i want to convert it into http://localhost/Seo/blog/cat/SEO
extension are removed but next blog part is not working
You're missing a "cat" in your rule:
RewriteRule ^blog/cat/([a-zA-Z]+)/$ blog.php?cat=$2
Since your URLs are going to look like http //localhost/Seo/blog/cat/SEO
Additionally, you'll want to put that rule before the rules that you already have.