Serious issue in URL rewriting

Discuss practical ways rearrange URLs using mod_rewrite.

Serious issue in URL rewriting

Postby sajjad27s » Mon Aug 25, 2008 9:12 pm

Hi

I need to implement a rewrite rule like this.

If user enters this:

http://www.mywebsite.com/anydomain.com

then I need this URL to rewrite in

http://www.mywebsite.com/mypage.php?d=anydomain.com


(NOTE: anydomain.com can be any domain name or any tld.)


Thanks.
sajjad27s
 
Posts: 4
Joined: Mon Aug 25, 2008 9:10 pm

Working on my local PC

Postby sajjad27s » Mon Aug 25, 2008 9:14 pm

I am also sending you my local htaccess. So you can better understand the thing. This is working fine on my PC. ("domain" is the Alias defined in apache config file. So I type http://mypc/domain/yahoo.com for example)


RewriteEngine on

# For local PC only
RewriteBase /domain

# ------ To stop rewriting on other files in the folder -------------
RewriteRule ^.*\.php.* - [L]
RewriteRule ^.*\.html - [L]
RewriteRule ^.*\.css - [L]
RewriteRule ^.*\.jpg - [L]
# Actual rule for domain names
RewriteRule ^(.*\.[a-z]+) mypage.php?d=$1 [L]
sajjad27s
 
Posts: 4
Joined: Mon Aug 25, 2008 9:10 pm

Solutions found on other forums

Postby sajjad27s » Mon Aug 25, 2008 9:17 pm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# spikeZ version
# RewriteRule ^mywebsite.com/([a-zA-Z0-9_.]+)?/? mywebsite.com/mypage.com?d=$1 [L]

# corrected version
# RewriteRule ^/?([a-zA-Z0-9_.]+)?/? mypage.php?d=$1 [L]

# "garbage collector" version
# (not much different than spikeZ corrected version)
RewriteRule ^/?(.*)$ mypage.php?d=$1 [L]


The above given different rules have been implemented but still not working.

Please help !
sajjad27s
 
Posts: 4
Joined: Mon Aug 25, 2008 9:10 pm

Postby richardk » Tue Aug 26, 2008 11:18 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteBase /domain

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+\.[a-z]+)$ ./mypage.php?d=$1 [NC,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Nothing is working

Postby sajjad27s » Wed Aug 27, 2008 2:23 am

Tried the above one but not working.

Someone else has given

RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9\-]+)\.com$
RewriteRule ^(.*)$ /mypage.php?d=%1 [R,L]

(R is used just to check the thing)

Using this, if I enter

www.mysite.com/yahoo.com

it goes to the right page but eats up the .com from yahoo.com and only returns yahoo to the page.

Any solution ? I need to pass any doman (any TLD) to the page.
sajjad27s
 
Posts: 4
Joined: Mon Aug 25, 2008 9:10 pm

Postby richardk » Fri Aug 29, 2008 7:29 am

What exactly happened when you tried what i gave you? A 404 error? A 500 error?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+\.[a-z]+)$ /mypage.php?d=$1 [NC,R,L]

and
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/mypage\.php$ [NC]
RewriteRule ^(.+\.[a-z]+)$ /mypage.php?d=$1 [NC,R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 3 guests

cron