Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:57:15+00:00 2026-05-27T15:57:15+00:00

Following is the Folder Structure of my PHP Project PHPProject (Root) –>Admin/ –>Config/ –>File1.php

  • 0

Following is the Folder Structure of my PHP Project

PHPProject (Root)
-->Admin/
-->Config/
-->File1.php
-->File2.php
--> ..
--> ..
-->.htaccess
-->File10.php

I would like to enable RewriteURL for the project that can be accessed in the following manner.

Rule 1:
My Domain should always be accessed with http://www.mydomain.com. If someone tries to access as http://mydomain.com i will have to rewrite the URL to http://www.mydomain.com. For which I am using the following rule on my htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
#RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
</IfModule>

Rule 2:
I would like to have a specific URL that points to a page:

http://www.mydomain.com/username to rewrite to http://www.mydomain.com/file4.php?name=username

Rule 3:

I am able to get the first rule to work properly with the above information on .htaccess file, but the problem is I have to hardcode the domain name on it. Would it be possible to specify a generic (regex) so that the rule applies to multiple domain?

Question:
I require help to combine Rule 1 + Rule 2 + Rule 3 altogether as rules on my .htaccess file.

Could someone please help me acheive this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:57:16+00:00Added an answer on May 27, 2026 at 3:57 pm

    Rule 1:

    RewriteCond %{HTTP_HOST} !^www\.(domain1|domain2|domain3|domain4)\.com [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    

    or:

    RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC]
    RewriteCond %{HTTP_HOST} !^www\.domain2\.com [NC]
    RewriteCond %{HTTP_HOST} !^www\.domain3\.com [NC]
    RewriteCond %{HTTP_HOST} !^www\.domain4\.com [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    

    Rule 2

    http://www.mydomain.com/username

    to

    http://www.mydomain.com/file4.php?name=username

    RewriteRule ^username$ /file4.php?name=username [QSA,NC,L]
    

    and if you want to make it generic (with alphanum chars):

    RewriteRule ^([a-z0-9]+)$ /file4.php?name=$1 [QSA,NC,L]
    

    Rule 3

    Get all together:

    RewriteCond %{HTTP_HOST} !^www\.(domain1|domain2|domain3|domain4)\.com [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    
    RewriteRule ^([a-z0-9]+)$ /file4.php?name=$1 [QSA,NC,L]
    

    Hope this helps.

    Two hints:

    Please try to use the RewriteLog directive: it helps you to track down such problems:

    # Trace:
    # (!) file gets big quickly, remove in prod environments:
    RewriteLog "/web/logs/mywebsite.rewrite.log"
    RewriteLogLevel 9
    RewriteEngine On
    

    My favorite tool to check for regexp:

    http://www.quanetic.com/Regex (don’t forget to choose ereg(POSIX) instead of preg(PCRE)!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following folder structure: project src code.c makefile bin How can I compile
Suppose I have the following (desired) folder structure: *CommonProject *Project#1 ----> CommonProject(link) *Project#2 ---->
I have the following directory structure of a project: Folder project in Eclipse: --folder
I would like to know following: I added the folder Graphics into my project
i 've the following folder structure src\BAT\templates\admin\base.html src\BAT\media\base.css src\BAT\media\admin-media\base.css settings.py MEDIA_ROOT = os.path.join( APP_DIR,
Trying to get a simple test perl script working. Have the following files/folder structure
Using PHP 5.3.3 (stable) on Linux CentOS 5.5. Here's my folder structure: www/myFolder/ www/myFolder/testFolder/
I'm using Iirf v2.0 . I have the following directory structure: / /library /library/index.php
I have got following folder structure for my domain (domain.com): /data/images (it´s subdomain name,
i'm getting following error in my PHP file. Warning: include(../config/config.php) [function.include]: failed to open

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.