wordpress url rewriting issue for one page or post - php

I need help on wordpress Rewirite url.
http://www.example.com/this-is-a-test-title/93/
http://www.example.com/this-is-a-test-title2/93/
http://www.example.com/this-is-a-test-title3/93/
All these urls should point to
http://www.example.com/?p=93
any string after example.com/%%%%%%/93 should needs to point to
http://www.example.com/?p=93
Its should works only particular post id = 93 Only.

You may need to use couple of rewrite rules in web site .htaccess file, this file should be placed in root server directory. The mod_rewrite is an Apache module for manipulating (rewriting) URLs. Frequently this means taking the URL requested by a visitor and sending them content at a different URL.
Example:
Original URL:
http://www.example.com/old-page/
Desired destination URL:
http://www.example.com/new-page/
The .htaccess syntax:
RewriteEngine On
RewriteRule ^old-page/?$ $1/new-page$2 [R=301,L]
More info here.

Create an .htaccess and add the below rules in the file
Redirect 301 /this-is-a-test-title/93/ http://www.example.com/?p=93
Redirect 301 /this-is-a-test-title2/93/ http://www.example.com/?p=93
Redirect 301 /this-is-a-test-title3/93/ http://www.example.com/?p=93

there are plugins which help with these kind of redirects.
For e.g.
https://wordpress.org/plugins/quick-pagepost-redirect-plugin/

Related

htaccess redirect url to parent directory

I am getting an issue on my website. Google indexes many this kind of URLs:
http://example.com/folder/url1.php/url2.php
So, how can I redirect to my original URL, which in this case is:
http://example.com/folder/url1.php
There is another folder2 also in folder and only redirect if there is another url appended after url1.php
Frankly speaking, I am really new to this htaccess redirect, I never used this before.
So, any help will be really appreciated.
You can use RedirectMatch directive to redirect your URLs.
At the top of your htaccess file, add the following line :
RedirectMatch 301 ^/folder/([^/]+)/([^/]+)\.php$ https://example.com/folder/$1
To redirect a particular/single URI , you can use
RedirectMatch 301 ^/folder/file.php/file.php$ https://example.com/folder/file.php

Magento htaccess redirection issue

I was trying to redirect a particular URL and all its child URL's to a particular URL. Using 301 redirection this is working fine but the browser URL is showing the test contents also. Please see below for more details
Example: https://www.mywebsite.com/customer/account/login/referer/* needs to be redirected towards https://www.mywebsite.com/customer/account/login/register
What I tried is:
Options +FollowSymLinks
RewriteEngine on
Redirect 301 /customer/account/login/referer https://mywebsite.com/customer/account/login/register
The htaccess rule is working fine for just this URL. If I type
https://mywebsite.com/customer/account/login/referer/testing
This will be redirected towards https://mywebsite.com/customer/account/login/register/test
Please let me know how I will be able to trim the other part (URL part after register/*)from the redirected URL. What I am trying to achieve is
https://mywebsite.com/customer/account/login/referer/* [ANY URL's AFTER referer/ (Including /referer) needs to be redirected to https://mywebsite.com/customer/account/login/register].
This is expected behaviour, as stated in the documentation of Redirect
Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.
To redirect all requests starting with this prefix to the given URL, you may use RedirectMatch, which uses regular expressions instead of a URL prefix
RedirectMatch ^/customer/account/login/referer https://mywebsite.com/customer/account/login/register
You don't need to use
Options +FollowSymLinks
RewriteEngine on
because this is for mod_rewrite. Redirect and RedirectMatch are provided by the mod_alias module.

Need to redirect a bad URL to a good URL in the same hosting which uses different domain

The question is simple:
I have had a temporary domain name to put a website live before changing the current hosting of the client (for various issues with previous hosting).
So the website was live for a while using a bad URL, like:
http://www.morphartsolution.com/tau2015/
It stayed like this a few months, google put the bad URL in search results. Now that the website is live at:
http://www.marchestau.com
I would like to remove any reference to morphartsolution.com/tau2015/ . In order to do this naturally I thought to do a .htaccess redirect from morphartsolution.com/tau2015/ to marchestau.com but couldn't work it out properly.
Both morphartsolution and marchestau domains are in the same hosting (server), morphartsolution being the main domain name and marchestau an additionnal domain that works inside the tau2015/ folder.
Any clue as what would be the magic line to put in .htaccess for this?
Thanks!
You need a permanent redirect from
http://olddomain.com/tau2015/
to
http://www.marchestau.com
Add the following line to your htaccess :
Redirect 301 /tau2015 http://www.marchestau.com
If the above redirect fails, try mod-rewrite :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldddomain.com$
RewriteRule ^tau2015/(.*)$ http://www.marchestau.com/$1 [NE,L,R=301]
I think you want to redirect every page at http://www.morphartsolution.com/tau2015/ to http://www.marchestau.com/ as it is , for example , http://www.morphartsolution.com/tau2015/example.php to http://www.marchestau.com/example.php
So put the following code inside htaccess # tau2015 folder
RewriteEngine On
RewriteRule ^(.*)$ http://www.marchestau.com/ [R=301]

301 Redirect: index.php

I am familiar with redirecting URLs that don't have file types at the end, but not with ones that have .php at the end.
The website I'm working on has hundreds of indexed pages on Google that have this at the beginning of the url: http://example.com/index.php? with more information trailing afterwards.
An example is: http://example.com/index.php?main_page=index&cPath=1_18
The new index of the website is http://example.com/index or http://example.com
If I put http://example.com/index.php as the URL to be redirected, will it also redirect all index.php? Or do I need to put http://example.com/index.php* as the URL to be redirected or http://example.com/index.php?*?
Thank you!
If the main script to be executed is index.php, then there is no point in redirecting a url to itself...
Aabout those GET parameters in the url, if index.php oesn't use them, then.... they will be useless, but... thats it XD
The point is: does everything work without redirecting? If so, why redirecting at all?
If there are 301 redirects, ... that will mean more request to the server, and for those clients with low bandwith it does make a difference.
BTW, take a look at: htaccessredirect
Try:
RedirectMatch 301 ^/index\.php$ /
(or)
RedirectMatch 301 ^/index\.php$ /index
The query string at the end will automatically get appended.
If you're using wordpress now, you're not going to be able to use the mod_alias directive like above. You'll need to use mod_rewrite and place these rules above the wordpress rules:
RewriteCond %{THE_REQUEST} \ /+index\.php
RewriteRule ^ / [L,R=301]
(or replace the / at the end with /index)

Htaccess wrongly making 301 redirect

I'm just trying to display css content at http://mydomain.com/dynamic_css/presets/
when user's browser loads http://mydomain.com/css/dynamic.css using the following
RewriteEngine on
RewriteRule ^dynamic\.css$ http://mydomain.com/dynamic_css/presets/ [QSA,L]
But instead browser gets http 301 redirected to http://mydomain.com/dynamic_css/presets/
Any idea why ?
Basically, the script at http://mydomain.com/dynamic_css/presets/ shows up a CSS generated code to allow more styles control from admin settings.
You can't specify the full domain in your request. mod_rewrite assumes this is an external URL which can only be handled via redirect. Try the below instead.
RewriteRule ^dynamic\.css$ /dynamic_css/presets/ [QSA,L]

Categories