.htaccess and redirect urls - .htaccess

I have used the following to rewrite urls on my website
RewriteRule writers/(.*)/ writer-pages.php?page_name=$1
RewriteRule writers/(.*) writer-pages.php?page_name=$1
which works fine, but I have old pages that have an extension /writers/name-here.php and the rewrite above removes the .php how can I redirect the old .php to the the urls without the extension.
Another problem is I don't want redirect all .php pages
Any idea how I can do this. Any help would be much appreciated

RewriteRule writers/(.*).php writers/$1/
you can test your rewrite rules at rewrite-rule-tester

Your 2 rules can be combined into one.
You need an additional rule.
Here is the code:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /+writer-pages\.php\?page_name=([^\s&]+) [NC]
RewriteRule ^ writers/%1? [R=302,L]
# your original rule
RewriteRule writers/([^/]*)/?$ writer-pages.php?page_name=$1 [L,QSA]

Related

Adding parameters to a .htaccess redirect

I'm trying to redirect a url but I can't seem to make it work for some reason. I'm trying to redirect my.domain.com/rss/abc/ to my.domain.com/rss/abc/?type=555
I've put this in my .htaccess
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/rss/abc/?$ /rss/abc/?type=555 [R=301,L]
Any pointers ? This is on a old TYPO3 site. Anyway it could hijack the request before doing the redirect ?
I can only recommend to use some kind of online htaccess rewrite rule checker, for example https://htaccess.madewithlove.com/ (not the only one, and no real preferance or recommendation about others).
Your rewrite rule is wrong, it should be:
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^rss/abc/?$ /rss/abc/?type=555 [R=301,L]

Dynamic url's redirect from old to new url's using .htaccess

I want to redirect below two dynamic url from old url's to new url's using .htaccess and i have done this application using codeigniter.
1) This are the dynamic url's and there are more than thousands of url's in my database.
Old(From) URL
https://www.example.com/area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001
2) This are the amp version of the above url.
Old(From) URL
https://www.example.com/amp-area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001/amp
I have tried with below code
RewriteRule ^area-name$ http://www.example.com/area-name [R=301,L]
RewriteRule ^amp-area-name$ http://www.example.com/amp-area-name [R=301,L]
But not redirecting to the new urls. How can do this redirect using .htaccess.
Keep these 2 redirect rules just below RewriteEngine line:
RewriteEngine On
RewriteRule ^area-name/(.+)$ /$1 [R=301,L,NC,NE]
RewriteRule ^amp-area-name/(.+)$ /$1/amp [R=301,L,NC,NE]
# remaining rules go below this
Try This
RewriteRule ^area-name/pangothe-263001/?$ $1/pangothe-263001$2 [R=301,L]
Try with below rules,
Canonical links Redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/area-name/(.*)$
AMP links Redirect
RewriteRule ^ https://www.example.com/%1 [R=301]
RewriteCond %{REQUEST_URI} ^/amp-area-name/(.*)$
RewriteRule ^ https://www.example.com/%1/amp [R=301]

.htaccess 301 redirect with exceptions

I have converted my asp site to php recently.
URLs remained the same, but obviously mysite.com//.asp pages became mysite.com//.php
I used this .htaccess entry to redirect (and it works perfectly):
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.asp$ $1.php [R=301, L]
My problem is, that I had to change some of the old URLs, so the above rule doesn't function properly.
Is it possible to add additional rules to .htacces, that overwrite the above global rule?
Like
Redirect 301 /path/page.asp mysite.com/path/page_new.php
and if possible, where to put it?
Thank you.
Stick with mod_rewrite since you're already using it and not through mod_alias(Redirect) into the mix.
Just add the URL's you want redirect specifically before your catchall rule.
RewriteEngine on
RewriteBase /
RewriteRule ^specific\.asp$ /path/page_new.php [R=301,L]
RewriteRule ^specific2\.asp$ /path/page_new2.php [R=301,L]
RewriteRule ^(.*)\.asp$ $1.php [R=301, L]
Let me know how this works out.

Subdomain adding a folder to .htaccess

I'm trying to redirect...
http://blog.example.org/folder/name-of-page.html
...to....
http://www.example.org/different-name-of-page.html
For my .htaccess file under blog.example.org I've added...
Redirect 301 /folder/name-of-page.html http://www.example.org/different-name-of-page.html
However, when I do this it takes me to http://www.example.org/blog/folder/different-name-of-page.html
For some reason it's auto-populating the /blog/folder/ part instead of taking me to the URL I've suggested.
Any idea on a fix?
It looks like it's interferring with rewrite rules that you have that map subdomains to folders. Use mod_rewrite instead of the Redirect directive.
Before any of your other rules, add:
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} /folder/name-of-page\.html
RewriteRule ^ http://www.example.org/different-name-of-page.html [L,R]

How to redirect a page without the page extension

I am currently working on a signup page and I was wondering if I could modify the URL without the .php extension.
For example, it is now
www.xyz.com/signup.php
And what I would like achieve is
www.xyz.com/signup
Now I am assuming that I might have to use the htaccess file, but I am not sure about it.
First rule will redirect from signup.php to domain.com/signup/.
Second rule will redirect internally so the URL will remain domain.com/signup/ while displaying the content of domain.com/signup.php.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /signup.php to /signup/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+signup\.php\s [NC]
RewriteRule ^ /signup/? [R=302,L]
# Internally forward /signup/ to /signup.php
RewriteRule ^signup/?$ /signup.php [NC,L]
What you're looking for is called URL rewrite. Take a look at this tutorial for beginners: http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/.
You can duplicate with .htaccess
RewriteEngine On
RewriteRule singup$ singup.php [NC,L]

Resources