htaccess mod_rewrite Shorten to a SEO friendly URL - apache

I have this address
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
that I would like to make it a lot shorter and more SEO friendly to something like (I don't know ... open to suggestions) http://www.nfrases.com/tag/10/508 or http://www.tag10name.nfrases.com/508
I need help with how to code this, because a simple thing as trying to make the address always http://www.nfrases.com case the user goes to http://nfrases.com or www.nfrases.com I tried and failed :(
Used this code by the way:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]

http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
becomes
http://www.nfrases.com/10/508
with this in your .htaccess
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /tag.php?id_tag=$1&id_frase=$2 [L,QSA]
Untested. Let me know if it works for you.

Related

.htaccess rewrite rule with pagination

I'm trying to write a mod-rewrite rule to handle pagination links on my site.
I'd like my url structure to be this: http://www.mysite.com/classifieds/state/example?page=2
I've tried the following: ^classifieds/city/(.*)?page=(.*) classifieds.php?state=$1&page=$2 [L]
Any guidance would be much appreciated. Thanks
You will need QSA flag to carry over existing query string.
Try this rule:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^classifieds/state/([^/]+)/?$ classifieds.php?state=$1 [L,QSA]
RewriteRule ^classifieds/city/([^/]+)/?$ classifieds.php?city=$1 [L,QSA]

htaccess seo friendly urls, mod rewrite, redirection

I'm currently trying to make SEO friendly URL's for very specific URL's, not all of them. I've been at this for 48 hours with no luck. My goal is to make http://mydomain.com/index.php?p=g&id=1 look like this; http://mydomain.com/pageone/ - so far I have been able to achieve the redirection thusfar, but it is showing a 404 "The requested URL /pageone/ was not found on this server". My question is how to make it redirect to the virtual directory and not throw a 404.
Please note I want to add a rule for each page id, not a rule that changes everything from index.php?p=g&id=, just each specific link.
Below is my htaccess code:
Options +FollowSymLinks
Options -Multiviews
RewriteOptions MaxRedirects=1
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=g&id=1$ [NC]
RewriteRule ^index\.php$ /pageone/? [r=301,nc]
Any help with this would be GREATLY appreciated.
You redirected the index.php to /pageone/ but did not define what /pageone/ will actually show. You should add the following line to your .htaccess:
RewriteRule ^pageone/?$ index.php?p=g&id=1 [L]
and remove your rule. If you want to keep both RewriteRules, then add the following lines right after RewriteEngine On:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

Mod_rewrite rewrite URL doesn't do anything

For some reason Apache doesn't rewrite my URL's and I can't figure out what's wrong.
I can confirm that mod_rewrite works because this works:
RewriteEngine on
RewriteRule ^oranges.html$ apples.html
And it shows the apples.html page.
I am trying to use this but it doesn't do anything!
Options -Multiviews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)[/]*$ index.php?page=$1
To look like this: http://example.com/search/
What could be wrong here? :o

.htaccess for unknowns

Alright, so here is what I'm hoping for...
Any request to this
http://www.fileorchard.com/3451928347592
will rewrite to http://www.website.com/joke.php?j=3451928347592
but also, I would like this to be possible as well
http://www.website.com/3451928347592-dswkfjawe/asdoiw-aweofiwe
Essentially, I would like to grab the numbers, and ignore anything after them.
This is what I have so far
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)/?$ joke.php?j=$1 [NC]
This works for just the simple http://www.website.com/3451928347592
but the rest don't work.
Thanks.
Maybe RewriteRule ^([0-9]+)(.*)/?$ joke.php?j=$1 [NC] ?

Re-writing URL's with Query Parameters such as Product ID's

There is so much content on the web for URL re-writes based on a number of scenario's that it makes it difficult to locate a solution to a specific query.
I'm just trying to clarify what the 'best' way to re-write URL's with query parameters to 'search engine friendly' URL's would be when using mod_rewrite on an apache server.
For example:
http://www.mydomain.com/product.php?pid=130
Would something like the following in .htaccess rewrite the above URL to a search engine friendly version?
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{QUERY_STRING} ^pid=130$
RewriteRule ^$ /productid-130.html [L]
Any advice on this would be greatly appreciated.
Thanks in advance.
try adding the following to your .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#if it is a productid html url, then capture the productid
RewriteCond %{REQUEST_URI} ^/productid-([0-9]+)\.html$ [NC]
#and rewrite to product.php with id
RewriteRule . product.php?pid=%1 [L]