This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 3 years ago.
i want to rewrite url from page.php?id=something-new-url-5dd669f4882a6 to domain.com/something-new-url-5dd669f4882a6
i have done some htaccess practices but it is not working.
here are my codes.
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/page\.php\?id=(.*)\s [NC]
RewriteRule ^ /%1? [R=301,L]
my project is in directory like ,
www.example.com/demo/page.php?id=something-new-url-5dd669f4882a6
and i want to make it seo friendly
domain.com/demo/something-new-url-5dd669f4882a6
Look this: redirect in php
Page.php:
<php>
$tb=explode('=', $_GET);
if (isset($tb[1]) && $tb[0]=='id') header('Location: domain.com/demo/' . $tb[1]);
exit();
</php>
Related
This question already has answers here:
301 Redirect to remove query string on homepage only
(1 answer)
Rewrite from any query string after root to root in .htaccess
(2 answers)
Closed 10 months ago.
I am using parameters on some subpages, but google index them in the search results for some reason in the homepage URL.
How can I please remove them in .htaccess only for homepage?
remove ?a=123 here:
example.com/?a=123 (result: example.com)
don't remove it here:
example.com/subpage/event.php?a=123
I found this, but I don't know how to apply it only for homepage:
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?
Use this:
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^/?$ / [R=301,L,QSD]
%{QUERY_STRING} . means "query string contains at least one character"
^/?$ is "just the home page" -- ie the URL path only consists of an optional slash
[R=301] Redirects the request (to change the URL)
[L] is the last rewrite rule so that it doesn't conflict with later ones
[QSD] is "query string delete" so that rewrite doesn't try to append the query string to the redirect
This question already has answers here:
How to create friendly URL in php?
(8 answers)
Closed 1 year ago.
I am trying to implement SEO friendly URLs using .htaccess and PHP.
My URL is:
http://www.my_web_site.com/instructions.php?topic_id=6&category=NNNX&t=a-b-c
I want to this:
http://www.my_web_site/6/a-b-c
Can someone please help me make a following .htaccess content
Thanks.
You can use the following rule in your htaccess file to shorten your URLs
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)$ /instructions.php?topic_id=$1&category=NNNX&t=$2 [L]
With this rule , you can just type example.com/6/foobar instead of the full old URL path.
This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 4 years ago.
HOw to make this url:
http://localhost/TrustyWrenchVersionOOP/?page=home
to this url:
http://localhost/TrustyWrenchVersionOOP/home
Rewrite your .htaccess rules like so. This is what I use and it works fine. There's different ways to achieve this, a quick google search probably would've yielded quicker results though
RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
This question already has answers here:
Remove .php extension with .htaccess
(17 answers)
Closed 4 years ago.
My URLs look like this:
mywebsite.com/subpage-name.php
I want my new links to look like this:
mywebsite.com/subpage-name/
How can I redirect all my ".php" pages to "/" pages?
You have to add a RewriteRule in your .htaccess with a regex.
RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]
Make sure to add
RewriteEngine on
Before applying the redirect rule.
Happy Coding.
This question already has answers here:
How to redirect non-www to www URL's using htaccess?
(4 answers)
Closed 8 years ago.
I would like to use .htaccess to point any calls to http://example.com/ to http://www.example.com including whether a page is specified. That is, http://example.com/contact.html would redirect to to http://www.example.com/contact.html.
Can someone help with the syntax as I've tried different examples and it won't work.
You can use this, it'll work on any domain without editing:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Source
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Trivia: If you are using an example or placeholder domain, please use example.com. This domain has been reserved specifically for this purpose in RFC2606.
I've written a small Apache plugin that might be helpful here, it's called "RedirToServName" and can be found in my software dump at http://www.hogyros.de/download/ . Documentation is a bit lacking; in essence all it does is generate redirects if the host name is not the canonical hostname from the ServerName directive.
Granted, using a dedicated plugin for that seems like overkill, but I find that it leaves less room for misconfiguration, as the only configuration variable is a boolean to turn it on.