Rewriting friendly URL's using .htaccess [duplicate] - .htaccess

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Shorten the URL from example.com/page.php?var=letters to example.com/letters
Using htaccess, is it possible to redirect from:
http://www.mydomain/123456
to
http://www.mydomain/myscript.php?id=123456
Any help would be much appreciated.

You can use rewrite mod :
RewriteRule ^(\d+)$ myscript.php?id=$1

Related

.htaccess rewriting a URL which is passing parameters [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 2 years ago.
Assume that i'm having a URL like this
example.com/demo/index.php?name=test
Now I need to rewrite the above URL like this,
example.com/demo/test
My question is, how can I achieve that by .htaccess URL rewriting?
yuppp, I got it
RewriteRule ^demo/([\w-]+)$ demo.php?id=$1
Credit to : #Abhishek Gurjar
RewriteEngine On
RewriteRule ^test/(.+) /test.php?name=$1 [L]
you must add bove code in htaccess and you can get parameter as $_GET['name']

How to redirect www.domain.com/.html to www.domain.com [duplicate]

This question already has answers here:
.htaccess redirect FROM subfolder to domain name
(5 answers)
Closed 4 years ago.
I'm having problems with this kind of url
www.domain.com/.html
I have a Google Search Console issue telling me that I have problems with that url. I want to make a 301 redirect to the root of the website
From www.domain.com/.html to www.domain.com
Finally it was a 403 error (forbidden). Solved in httaccess with ErrorDocument 403 / redirection.

Virtual Folders [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm trying to utilise mod_rewrite allowing me to use domain.com/d4k1d to give the same effect as domain.com/link.php?link=d4k1d
At the moment I have this in my .htaccess although this seems to give me 404 errors.
RewriteEngine on
RewriteRule /(abcdefghijklmnopqrstuvwxyz[0-9]+)/ link.php?link=$1
I'm not too familiar with mod_rewrite etc. so I don't know where to go with this :S.
You need to include all of the letters inside of the character class (which can also be simplified). Your current rule only allows for a letter followed by one or more numbers:
RewriteEngine on
RewriteRule /([a-z0-9]+)/ link.php?link=$1
You need to remove the leading slash because it's stripped from the URI by apache before being used in rules that are in an htaccess file.
RewriteEngine on
RewriteRule ^([a-z0-9]+)/?$ /link.php?link=$1 [L]

.htaccess: Replace part of url [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've got some duplicate content and want to redirect to the right url (remove a part of the url and redirect)
Examples:
http://www.domain.com/en/url/1-url
http://www.domain.com/es/url/1-url
http://www.domain.com/fr/url/1-url
....
The individually should redirected to:
http://www.domain.com/en/url
http://www.domain.com/es/url
http://www.domain.com/fr/url
....
Because I have to do this for a lot of urls, I can't redirect them each manually and need a rule which detects if the url contains "/1-url" and if yes remove this part from the url - but only this part.
Would be great if a mod-rewrite hero can help me with this. I'm searching for solution over .htaccess via a rewrite rule.
Check this:
RewriteRule (\w{2})/([^/]+)/\d+-[^/]+$ /$1/$2 [R=301,L]
RewriteRule ([^/]+)/\d+-[^/]+$ /$1 [R=301,L]
If you use a imported file to each 1-url page only add redirect method to imported file.
For example your every 1-url page have header.php, add redirect function to header.php

How To Use 301 Redirect In htaccess To Stop 404 Errors? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've two domains with same name but different TLD like .com and .net.
i'm using blog on ".com" domain and forum on ".net" domains like
Sites 1: "http://www.mywebsite.com/" (blog)
Site 2: "http://www.mywebsite.net/forum" (forum)
I'm facing problem with Google webmaster tool, webmaster tool trying to crawle my .com domain as forum hosted like "www.mydomain.com/forum" however forum not exist on .com domain. its exist on .net domain. so its generate 404 errors.
Please, let me know some code to to redirect ".com/forum/ {Plus Queries} /" to exact ".net/forum/{ Destination }" i believe its help to mark remove 404 errors or help to prevent more errors.
however, today I've set my robots.txt to disable Google crawling on ".com/forum"
In the htaccess file in your document root for the .com domain, add:
Redirect 301 /forum http://www.mywebsite.net/forum
If both domains share the same document root, thus sharing the same htaccess file, then you'll need to do an additional check for the host by using mod_rewrite instead of mod_alias:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com$ [NC]
RewriteRule ^/?forum/(.*)$ http://www.mywebsite.net/forum/$1 [L,R=301]

Resources