.htaccess freindly url help on Rewrite - .htaccess

If I want to use .htaccess to rewriting this:
http://example.com/article.php?article_id=79
to this:
http://example.com/article/my-cool-and-special-article-79.html
what is the rewriting I need to do?

The problem is going to be that Apache will not be able to determine what friendly URL to use from an ID. I think what you want to do is to do the rewrite the other way. What CMS are you using?

Not a machine where I can test, so you may need to dink with it. But, it would look something like this:
RewriteCond $1 ^article [NC]
RewriteRule ^([a-zA-Z0-9\-]+)\-article\-([0-9]+)\.php$ /article.php?id=$2 [L]

Related

Urls rewriting for a multilingual webpages

My actual page structure is like this:
https://example.com/try
What would be the best .htaccess rules to convert it to:
https://example.com/fr/essayer or https://example.com/en/try
What I have tested:
RewriteRule ^(fr|en)/(.*)\.php$ $2.php?lang=$1 [L,QSA]
But I can't change the page name to the french one.
Thanks.
If you want to use URLs like https://example.com/fr/pageA or https://example.com/en/pageA while under the hood still serving up https://example.com/fr/pageA or https://example.com/pageA you could use a rule like this:
RewriteRule ^(en|fr|de)/(.+) $2 [QSA,L]
Demo here: http://htaccess.mwl.be?share=c26eb9b8-7d31-51df-9072-0f218032dba3
Note that this does not pass the language code over, you could achieve that like so if needed:
RewriteRule ^(en|fr|de)/(.+) $2?lang=$1 [QSA,L]

URL Rewrite is not working correctly in .htaccess

I am trying to create a rewrite in my .htaccess file for my wordpress site. I need
www.a3performance.com/fastestsuit
to point to
http://www.a3performance.com/legend-fastest-racing-suit/
I am trying this, but it doesn't seem to work?
RewriteRule ^fastestsuit/?$ legend-fastest-racing-suit [NC,L]
Seems that you need to use here Redirect from one folder to new folder.
Something like this:
RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]
Actually #labris idea worked. For some reason it took a bit for my server to register the .htaccess change.
RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]

How to rewrite any page to index page with requested URL as $_GET parameter

Something similar had been discussed here, but this is slight different.
How to tell .htaccess to rewrite any requested page (regardless of it's depth from the site root) with site's index page, but with requested URL as a $_GET parameter, so it can be further handled by php, depending on it's contents, or depending on URL itself.
I was trying something like
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*) index.php?page=$1
but obviously I do something wrong.
Thanks in advance.
Try working on your RegEx. Maybe something like this:
RewriteRule ^([a-zA-Z0-9\-]+)([\/]*)$ index.php?page=$1 [NC,QSA,L]
Basically you can generate the rewrite code using an online tool like http://www.webtoolhub.com/tn561403-htaccess-url-rewrite.aspx by entering the desired parameters. Just put the url structure and it will write the .htaccess code that you can use or modify according to your needs.

SEO Friendly URL Command in .htaccess

I have a dynamic page that looks like the following:
www.sitedomain.com/page.php?id=30&name=about_our_company
I want to make my website links SEO friendly by having something like the following:
www.sitedomain.com/about_our_company.html
Or
www.sitedomain.com/about_our_company
My question is: what regex/code I should have in the .htaccess file?
Thanks
This ofc has a fixed id of 30.
RewriteRule ^about_our_company/?$ /page.php?name=$1&id=30 [NC,L]
since /about_our_company doesn't include the ID, it's impossible to invent the ID correctly.
the way I do it in my own CMS is to have something like this in the .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]
then in index.php, use the $_REQUEST['page'] (assuming PHP) variable to find the right page details in the database
You could improve this to be more generic:
RewriteRule ^([^/]+)/([^/]+)?$ /page.php?id=$1&name=$2 [NC,L]
The following URL's would all match:
http://example.com/30/about_our_company
http://example.com/29/contact
http://example.com/10/our_work

how do i setup in htaccess products/item-name

my url currently looks like this
domain.com/products?product=item
and as for products i used
RewriteRule ^products$ products.php [L]
but i want to setup the url the first way do i keep the above rewrite or remove it if i want to use
the first method?
this is what i tried but it wont work
RewriteRule ^products/([a-zA-Z])$ products.php?product=$1 [L]
Try this:
RewriteEngine On
RewriteCond "%{REQUEST_URI}" "!products\.php"
RewriteRule "^products/([^/]+).*" "products.php?product=$1" [L,QSA,PT]
The [PT] is frequently forgotten.
If you're using Apache 2.2.12 or later, consider using the FallbackResource directive instead. See http://httpd.apache.org/docs/trunk/rewrite/remapping.html#fallback-resource for a more detailed description of the various options available to solve this problem.

Resources