htaccess rewrite non html request - php

I've migrate a dynamic .asp site to static site by using sitesucker osx app...
everything works done if you access directly!
old url:
http://www.mysite.com/content.asp?L=1&IdMen=158‎
new url:
http://www.mysite.com/content.asp-L=1&IdMen=158‎.html
i get page not found from my old referral inbound links (google, yahoo etc...)
i would like, by using .htaccess, redirect all links that not contains ".html" to permanent redirect too html page...
i've tried this but not work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.html
RewriteRule ^(.*)$ $1.html [R=301,L]
many thanks
Frankie

As per examples if you want to modify query string then you need this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} !\.html$ [NC]
RewriteRule !\.html$ %{REQUEST_URI}-%{QUERY_STRING}.html? [L,R=301,NE]

Related

Send specific request uri to subdirectory using htaccess

I need to find a way to redirect all requests that contain the following URL:
http://local.testdomain/quality/
to use the appropriate files in {Document_Root}/quality/
ie. user requests http://local.testdomain/quality/assets/images/35.jpg
needs to get the file {public_folder}/quality/assets/images/35.jpg
What I've tried in the .htaccess file is
RewriteEngine on
RewriteCond %{HTTP_HOST} ^local.testdomain$
RewriteCond %{REQUEST_URI} !quality/
RewriteRule (.*) /quality/$1 [L]
but it doesn't seem to work.
I basically want to put a whole php project in Zend's public folder, and have that php project attainable via that request uri ({domain}/quality/)
Seems your htaccess is not correct.
Try something like :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^local.testdomain$ [NC]
RewriteCond %{REQUEST_URI} ^/quality/(.*)$
RewriteRule ^(.*)$ /PATH_TO_YOUR_PUBLIC_FOLDER/quality/$1 [L]
Let me know if it works
Best,

I want to redirect old url to new rewrite url using htaccess or php

I have a problem since i using rewrite url..
MY OLD URL:
Website.com/index.php?act=appdetail&appid=oWV
New Rewrite URL
http://website.com/angry_birds_rio-appdetail-oWVi.html
But all my old url are indexed in google and if any one come to my website its display the old URL and google also INDEXED the NEW URL. its make duplicate page on website problem.
Let me know the solution
My rewrite URL htaccess
RewriteEngine On
RewriteRule ^([^-])-([^-])-([^-])-([^-])-([^-]*).html$ index.php?appanme=$1&act=$2&appid=$3&page=$4&cat=$5 [L]
RewriteRule ^([^-])-([^-])-([^-])-([^-])-([^-])-([^-]).html$ index.php?appanme=$1&act=$2&appid=$3&page=$4&cat=$5&sString=$5 [L]
RewriteRule ^([^-])-([^-])-([^-]*).html$ index.php?appanme=$1&act=$2&appid=$3[L]
Here is your .htaccess file:
RewriteEngine on
RewriteRule ^/index.php?act=appdetail&appid=oWV$ http://website.com/angry_birds_rio-appdetail-oWVi.html [R=301,L]
You'll need to inform to web crawlers about the redirection, you cando it with a 301 code.
Appears the rule are .htaccess based; you need an additional set of rules to permanently redirect (301) BROWSER/CRAWLER requests for the index.php pages, if a set of CGI arguments are present, to the appropriate alias, this will tidy up Google in a few weeks. Then your rules above e.g.
RewriteEngine On
RewriteBase /
#Permanently redirect BROWSER requests for the index.php?xxx to the appropriate page alias:
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+)&page=([^&]+)&cat=([^&]+)&sString=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3-%4-%5-%6.html [R=301,L]
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+)&page=([^&]+)&cat=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3-%4-%5.html [R=301,L]
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3.html [R=301,L]
# Followed by: YOUR RULES FROM ABOVE
Note:
1) There appears to be a typo in YOUR second rule: sString=$6 NOT sString=$5
2) The Apache mod_rewrite documentation is worth a read if your unclear as to what the above rules do, or if you want something a little more abstract consider the following post.

Redirect using htaccess based on referrer

We only want users from a specific website to use our services. Is there a way to redirect all traffic that does not come from a specific referrer, to a website of our choosing, via htaccess?
Also, this is for the first page only. So if they get to our site, they're going to browse a new page, and their referrer for the new page would apparently be the site they are already on.
Thank you!
Try adding this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteRule ^/?first-page.html$ http://the-website-of-your-choosing.com/ [L,R]
You could also make it so you add your own domain to the referer check:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://your-domain.com [NC]
RewriteRule ^ http://the-website-of-your-choosing.com/ [L,R]
Then you can include all of your pages in the check.
Note that referers can be easily forged and any htaccess file using mod_rewrite in any of your subdirectories will supercede these rules (unless those htaccess files have the RewriteOptions inheret option set)
Didn't work for me, I've made this small change to redirect traffic from google:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.google\.(.*) [NC]
RewriteRule ^(.*)$ https://www.my-site.it/$1 [L,R]

mod_rewrite Friendly URL clashing with 404

I've been struggling with my mod_rewrite for a while now and I thought I'd cracked it…
My CMS generates blog post URLs with post.php?s= and I've been trying to remove this part of the URL so that they're nice and user friendly. Here's my mod_rewrite:
<ifModule mod_rewrite.c>
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www.tempertemper\.net$
RewriteCond %{REQUEST_URI} !cron.php
RewriteRule ^(.*)$ http://tempertemper.net/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^s=(.+)$
RewriteRule post.php /%1? [R=301,L]
RewriteRule ^resources /archive? [R=301,L]
RewriteCond %{REQUEST_URI} !post.php
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?s=$1
</ifModule>
Unfortunately, It seems to be directing all pages that aren't found to the blank post.php page instead of the error.php page.
My site is here: http://tempertemper.net and here's a URL that doesn't exist http://tempertemper.net/this-url-does-not-exist
It should take you to http://tempertemper.net/error
Thanks for taking a look :)
Because you are redirecting all paths which fit the [a-zA-Z0-9_-]+ pattern, this will simply send to your post.php script the query string s=this-url-does-not-exist. So it's up to your PHP script post.php to check whether this-is-not-a-url exists or not, as Apache cannot possibly know what blog post ID values are valid and which are not.
As a side note, I'd recommend using /blog/2012-08-24-whatever as the path you give to visitors, rather than /2012-08-24-whatever. That way you can reserve paths for other functions, such as /images without having to write a new exception in your .htaccess file every time you need to create a new utility path.

.htaccess Remove PHP get data from URL

Well I'm making profile pages so right now it looks like this
http://example.com/random/?user=Robert
What I want to do is remove ?user= from the URL so the page appears as
http://example.com/random/Robert
Iv'e searched and I can't find anything working for me.
Thanks!
Based on http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html this should do the trick:
RewriteCond %{QUERY_STRING} ^user=(.*)$ [NC]
RewriteRule ^random$ random/$1 [NC,L,R=301]
The first step is to make all of your links in this form http://example.com/random/Robert, then in the htaccess file in your document root, add:
RewriteEngine On
RewriteRule ^random/(.+)$ /random/?user=$1 [L]
But to handle 301 redirects to your old URLs, you can include this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /random/\?user=([^\ ]+)
RewriteRule ^random/$ /random/%1 [R=301,L]

Categories