301 redirect to correct url - regex

I have a lot of incorrect bad links and want to 301 redirect them to the correct one, the correct url are as follows:
Blockquote http://www.domain.com/string-video_string.html
the back links are pointing to:
Blockquote http://www.domain.com/string_string.html
any possible way to 301 redirect the wrong back links to the correct links?
Thank you in adance

You can use this rule in your site root .htaccess:
RedirectMatch 301 ^/([^_-]+)_(.+)$ /$1-video_$2

Depending on how you want to redirect (in which method; PHP, htaccess, etc.) you have some options.
I assume you're seeing 404 errors when users are trying to get to the links from an external source, like a search engine.
If that's the case, you can easily generate the code you need for which ever method you choose using this website:
http://www.rapidtables.com/web/tools/redirect-generator.htm
Make sure that you correctly format the URL's you want to redirect and it should work fine.
If you want to make sure your SEO issues get fixed, you should create a robots.txt file and place it in the root directory of your site (usually where the index file is) - and follow the instructions from this site: http://tools.seobook.com/robots-txt/ to de-index the bad links from the search engine. You may also want to create and submit (or resubmit) XML site maps to the search engines your users use most.

Related

Alternative to <!--#include virtual="somefilename"-->

I have a website running an an old apache server with SSI enabled. My host wants to move to a new server which has SSI disabled for security reasons.
I have a whole lot of pages with Google Friendly urls which just have one line
<!--#include virtual="Url_Including_Search_String"-->
What is the best alternative to the SSI to keep my google friendly search strings returning the specified search result?
I can achieve most of the results with rewrite rules in the .htaccess file, however some search strings have a space in the keyword but the url doesn't. I can't do this with a rewrite rule
ie www.somedomain.com.au/SYDNEY.htm would have
<!--#include virtual="/search.php?keyword=SYDNEY&Submit=SEARCH"-->
However,the issue is
www.somedomain.com.au/POTTSPOINT.htm would have
<!--#include virtual="/search.php?keyword=POTTS+POINT&Submit=SEARCH"-->
A rewrite rule cannot detect where a space should be in a Suburb name, so hoping there is an alternative for <!--#include virtual=
I have looked at RewriteMap but don't think I can access the file I would need to put this in.
I would use Mod Rewrite to redirect any calls to non-existent files to your Search page.
For example:
http://example.com/SYDNEY redirects to
http://example.com/search.php?q=SYDNEY
(assuming there is not actually a /SYDNEY/ file at your server root.)
Then get rid of all those individual redirect pages.
As for the spaces, I'd modify my actual Search page to recognize (for example) "POTTSPOINT" and figure out that the space should be inserted. Basically compare the search term against a database of substitutions.

Rewriting RewriteRule to include back one particular php file in the path

I inherited a large WordPress site: I was looking at the Wordfence live logs when I found users not loading a particular PHP page. I investigated and through an FTP client I found the file was where it was supposed to be. I used some network tool (in Chrome, Opera and Firefox) and, again, I found that file was returning a 404.
So, I found in the root of the website a short htaccess file containing this line:
RewriteRule ^wp-content/(.*)\.php$ [R=404,L]
I commented this out and reloaded the website: no error anymore. I must say, the error apparently doesn't cause anything strange to the website. But I would like to eliminate it.
I suppose this rule is meant to avoid someone can make a direct HTTP request to this and any other PHP file in that directory: in this case I suppose this file I'm talking about is called from an include, not directly, because in WordFence what I see is an error coming after a user accesses directly other pages, not this one in particular.
Anyway, I would like to rewrite this rule so that it stays the same as now, except for that php page. The PHP page is in the path of the theme:
wp-content/themes/themeName/core/css/customized.css.php
Is this possible? Any help is appreciated
If you want to exclude that specific php file from the RewriteRule, you can add a negative lookahead to the regex, like so:
RewriteRule ^wp-content/(?!themes/.*/core/css/customized\.css\.php$)(.*)\.php$ [R=404,L]

Use RegEx to redirect using data from files

Recently, we restructured a large site of one of our customers. This caused all the news-articels on that site to be on a different place. Problem is that the google cache is still showing them on the old location, leading to A LOT of 404 not founds ( its about 1400 news entries ).
Normally, a redirect using somewhat simple regex would be fine, but not only the path to the news did change, but also some parameters. Example:
Old Url:
http://www.customers-url.com/old/path/to/the/news/details/?tx_ttnews%5Btt_news%5D=67&cHash=a782f3027c4d00face6df122a76c38ed
How the new url should look like:
http://www.customers-url.com/new/path/to/news/?tx_news_pi1%5Bnews%5D=65
As you can see, the parameter D did change from 67 to 65 and the part of the URL before the ? did also change. Also, tx_ttnews has changed to tx_news and tt_news changed to news and the &cHash part did fall away completely.
I have the changed ids in a csv in the following format:
old_id, new_id
1,2
2,3
...etc...
Same goes the the changed url part before the ?. Since im not exactly an expert in using regex my question is:
Can this be done inside the .htaccess using RegEx ( not sure if it can even use a file as input)? How complicated is that? And how would such a regular expression look like?
Rather than trying to use .htaccess, it would be easier to manage and easier to code if you simply make a new page that responds on the old url (/old/path/to/the/news/details), then make that page build the new url and return a 301 to the browser with that new url.

Is there a "clean URL" (mod_rewrite) equivalent for iPlanet?

I'm working with Coldfusion (because I have to) and we use iPlanet 7 (because we have to), and I would like to pass clean URL's instead of the query-param junk (for numerous reasons). My problem is I don't have access to the overall obj.conf file, and was wondering if there were .htaccess equivalents I could pass on the fly per directory. Currently I am using Application.cfc to force the server to look at index.cfm in root before loading the requested page, but this requires a .cfm file is passed, so it just 404's out if the user provides /path/to/file but no extension. Ultimately, I would like to allow the user to pass domain.com/path/to/file but serve domain.com/index.cfm?q1=path&q2=to&q3=file. Any ideas?
You can mod_dir with the DirectoryIndex directive to set which page is served on /directory/ requests.
http://httpd.apache.org/docs/2.2/mod/mod_dir.html
I'm not sure what exists for iPlanet, haven't had to work with it before. But it would be possible to use a url like index.cfm/path/to/file, and pull the extra path information via the cgi.path_info variable. Not exactly what you're looking for, but cleaner that query-params.

Cherokee redirect

My server is running Cherokee and I'm trying to get a redirect to work. I'm running into troubles with infinite redirect loops because I am redirecting to the same folder.
My URL is:
http://domain.tld/example-variable (http://domain.tld/product-1234)
This needs to be redirected to:
http://domain.tld/index.php?item=variable (http://domain.tld/index.php?item-1234)
The Regex I have tried is:
^/product-(.*)
/index.php?item-$1
This redirect is working. However, http://domain.tld is now broken as well as files like images (http://domain.tld/image.jpg). Other redirects I'm using are working just fine, but they redirect a folder to another folder (i.e. /folderA to /folderB).
have you tried making the rule non-final and the ordering is correct? typically, those two will cause the sort of issue you're seeing.
#brent I've tried that indeed and all combinations I could think of where not solving the problem.
I ended up using a subdomain:
product.domain.tld/1234