Dynadot โ€” .com Registration $8.99

Mod rewrite error-need help

Spaceship Spaceship
Watch
Impact
19
hey
I am working on a website and I want to rewrite the URLS to make it more SEO friendly.
I was able to to convert anything.php to anything.html easily but i have a GET form on the website that returns the query like
site.com/view.php?site=WWW.SOMEWEBSITE.COM
I want it to rewrite it to something like "site.com/view/somewebsite.com"

I am using the following code, but it gives me a "Redirect LOOP" error

I am not sure if this can be done here but I also want it to error handle and strip anything before the "www." aswell
for example if the user types in "http://www.somesite.com" i want the url to be rewritten as "site.com/view/somesite.com" and if someone types in "www.somesite.com" the url will be written the same and finally..if someone types "somesite.com" the url will be rewritten the same
Also what would the PhP code look like for that? because after the url has been rewritten, i want to grab the site and do something with it..and i only want to get stuff after the "http://www." or "www."
thanks :)

Code:
RewriteEngine On
RewriteRule ([a-zA-z]+)\.html$ $1.php

RewriteCond %{REQUEST_URI} /view.php$

RewriteCond %{QUERY_STRING} ^site=([A-Za-z0-9\+]+)$

RewriteRule ^(.*)$ /s-%1? [R=301,L]

RewriteRule ^s-(.*)$ /view.php?site=$1 [L]
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
bump anyone?
 
0
•••
Hi,

This rule:

Code:
RewriteRule ^(.*)$ /s-%1? [R=301,L]

will be executed each time the redirect is performed. Therefore you'll end up redirecting to:

s-%1

then s-s-%1

then s-s-s-%1

etc.

If you reverse the last two lines you'll prevent this:

Code:
RewriteEngine On
RewriteRule ([a-zA-z]+)\.html$ $1.php

RewriteCond %{REQUEST_URI} /view.php$

RewriteCond %{QUERY_STRING} ^site=([A-Za-z0-9\+]+)$

[COLOR="Red"]RewriteRule ^s-(.*)$ /view.php?site=$1 [L]

RewriteRule ^(.*)$ /s-%1? [R=301,L][/COLOR]
 
0
•••
that made it worse
now its giving me the redirect loop on every page [including home page]
before it only gave me that error on "view.php" page
 
0
•••
Ooops. I caused the very problem I was trying to avoid :red:

I'm not sure what it is you are trying to do with these rules. Do you want to rewrite "http://yoursite.com/s-something" to "http://yoursite.com/view.php?site=something"? If so, you need this:

Code:
RewriteEngine On

RewriteRule ([a-zA-z]+)\.html$ $1.php

RewriteRule ^s-(.*)$ /view.php?site=$1

(the first RewriteRule is nothing to do with this problem, but I assume you need it for other reasons).
 
0
•••
no
I have a search form on my website that sends the user to
mysite.com/view.php?site=USERINPUT
i want to rewrite it so when someone searches something they go to
mysite.com/view/USERINPUT

now the user input must be a URL
if they search for "www.google.com" I want them to be redirected to
mysite.com/view/gooogle.com
[NOTE ThAT ThE WWW hAS BEEN STRIPPED OFF]
if they search for "http://www.google.com" or "http://google.com"
i want them to be redirected to the same
site.com/view/google.com
thanks
 
0
•••
I still don't get what you were trying to do with this rule:

Code:
RewriteRule ^s-(.*)$ /view.php?site=$1 [L]

That aside, to do exactly what I think you describe in the previous post, the following should work:

Code:
RewriteEngine On
RewriteRule ([a-zA-z]+)\.html$ $1.php

RewriteCond %{REQUEST_URI} /view.php$
RewriteCond %{QUERY_STRING} ^site=(http://)?([wW]{3}\.)?([A-Za-z0-9\.]+)$
RewriteRule ^(.*)$ /view/%3? [R=301,L]

I have changed the second RewriteCond to optionally handle the "http://" and "www." parts, and to accept dots in the site variable.

Now the user is redirected. We need another rule to rewrite the URL to a php script. Something like:

Code:
RewriteRule ^view/(.*)$ view2.php?site=$1 [L]

then a file called view2.php where you handle the :

Code:
<?php echo "User entered site ".strip_tags($_GET['site']); ?>

(strip_tags present to prevent XSS security problems)

The user submits the form to view.php, is redirected (the 301 part in the RewriteRule makes it a redirect) to view/something.com, this gets rewritten to view2.php?site=something.com. The distinction between "redirected" and "rewritten" is that redirect causes what is shown in the users address bar to change; rewrite doesn't.
 
0
•••
great it works
however i have 1 question now
all my links in the view page are now
"view/index.html" "view/faq.html" etc
instead of just "index.html" and "faq.html"
whats the easiest way of fixing that?
I fixed the CSS link by adding
PHP:
<link href=<?php echo '"'.$_SERVER["SITE_HTMLROOT"].'/default.css"';?> rel="stylesheet" type="text/css" />


---------- Post added at 01:33 PM ---------- Previous post was at 12:44 PM ----------

another thing
it only works if the user inputs "www.site.com" not "http://site.com" or "http://www.site.com"
it redirects them to
http://siteslogin.com/look.php?site=http://www.youtube.com
 
0
•••
Make them absolute references, not relative. The easiest way is probably to put a "/" at the beginning.

instead if:

Code:
<a href="index.html>Home</a>

put:

Code:
<a href="[COLOR="Red"]/[/COLOR]index.html>Home</a>
 
0
•••
okay
well the mod rewrite only works for "www.something.com" not "http://something.com" or "http://www.something.com"
 
0
•••
You have different/extra redirect code to that I posted since you now have a redirect to "look.php". Could you post your entire .htaccess file? Do you have a directory called "view" on your server? If so, try renaming it (it may have a .htaccess file which is conflicting).
 
0
•••
no i dont have a view directory
the entire code is
Code:
# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName siteslogin.com
AuthUserFile /home/siteslog/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/siteslog/public_html/_vti_pvt/service.grp
RewriteEngine On
RewriteRule ([a-zA-z]+)\.html$ $1.php
ErrorDocument 404 http://www.siteslogin.com/404.php
RewriteCond %{REQUEST_URI} /look.php$
RewriteCond %{QUERY_STRING} ^site=(http://)?([wW]{3}\.)?([A-Za-z0-9\.]+)$
RewriteRule ^(.*)$ /view/%3? [R=301,L]
RewriteRule ^view/(.*)$ view.php?site=$1 [L]
 
0
•••
The form is causing the query string to be URL encoded. This means instead of "http://" the query string is actually "http%3A%2F%2F". Try changing the condition to:

Code:
RewriteCond %{QUERY_STRING} ^site=(http%3[Aa]%2[Ff]%2[Ff])?([wW]{3}\.)?([A-Za-z0-9\.]+)$
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back