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 4110616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:57:26+00:00 2026-05-20T21:57:26+00:00

This is my .htaccess It feels like its way to long and that it

  • 0

This is my .htaccess It feels like its way to long and that it can be made more efficient. The problems I’m having at the moment are that because of the order these rules are in the Rewrites for profile view and vcard view aren’t working at the moment. I figured out that depending in what order I place these RewriteRules it will affect how the others behave. Its kinda of a nightmare if you ask me.

My site structure isn’t so complicated. I have 3 PHP pages each page handles different actions of my project using the $_GET values for checking that the person is in the right place with the right parameters. One thing I was having issues with was making friendly links so people can go to an image or something using familiar url paths.

Well thats it, oh ya. Also I have a dynamic RewriteRule template for when I want to use an option or a setting, then I can use the last 2 place holders to put in my data.

# Options:
# -MultiViews: Turns off multiviews so it doesn't interfer with our rewrite rules
# -Indexes: Stop directory listings
# +FollowSymlinks: Let out rewrite rules work
Options -MultiViews -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /

# Error page
# Force add trainling slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://foo.bar/$1/ [R=301,L]

# Prepent www if not exist in URI
RewriteCond %{HTTP_HOST} ^foo\.bar$
RewriteRule (.*) http://www.foo.bar/$1 [R=301,L]

# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC,OR]
RewriteCond %{REQUEST_FILENAME} -l [NC]
RewriteRule .* - [L]

# Rewrite for page view
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3 [QSA,L]

# Condition to ignore regular links
RewriteRule ^library/templates/([^/]+)/([^/]+)/([^/]+)/?$ library/templates/$1/$2/$3 [QSA,L]

# Rewrite for dynamic page settings
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3&$4=$5 [QSA,L]

# Rewrite for account view
RewriteRule ^([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2 [QSA,L]

# Rewrite for site default resources location
RewriteRule ^([^/]+)/([^/]+)/theme/s/([^/]+)/([^/]+)/([^/]+)/?$ library/themes/site/$3/$4/$5 [QSA,L]

# Rewrite for profile view
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [NC,L]

# Rewrite for vCard view
RewriteRule ^([^/]+)/vcard/?$ vcard.php?user=$1 [NC,L]


# Rewrite for user themes location
#RewriteRule ^([^/]+)/([^/]+)/theme/([^/]+)?$ library/themes/users/$3 [NC,L]

#error codes
#RewriteRule ^error/([^/]+)/?$ error.php?code=$1 [NC,L]
  • 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-20T21:57:27+00:00Added an answer on May 20, 2026 at 9:57 pm

    Since you have only one rule for each result URL, I don’t think you can simplify this — or not significantly — without altering your app’s URL structure. Your regexps are simple and, as far as I can tell, solid enough.

    But yes, the structure is fragile and order-dependent:

    • Two-part URLs can refer to account
      view or to vcard view. Which requires
      putting the account view rule after
      the vCard view rule AND avoiding ever
      having a user called “vcard”.
    • Five-part URLs can either be regular
      links or dynamic page settings — so
      avoid swapping these two rules or having a type “library” and a
      user “templates”.

    I wouldn’t worry much about efficiency/performance: in one of my projects we’re using a similar setup with 308 RewriteRule and 307 RewriteCond (just counted them). Having the same worry you have, I once measured its performance by running a load test with random URLs vs. the transformed ones and the difference in performance was so small that it was simply not measurable against the backdrop of PHP & database processing.


    Note: the fact that I have experience with something similar (strikingly similar I have to say) should not be construed to mean that I back it. URL structures which can’t be documented and explained easily are a nightmare and should be avoided if possible.

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

Sidebar

Related Questions

I have this .htaccess that I've been using to rewrite URLs like these: www.example.com/index.php?page=brand
Ok, so I have this .htaccess file that contains this <IfModule mod_rewrite.c> RewriteEngine On
I've this .htaccess file that move all the request to index.php?request=(URI) that elaborates them,
I'm building a Symfony application that's made to run many sites. Similar to this
How can I modify this htaccess file to exclude visitors with 2 different Ip
I'm having this .htaccess file: Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteBase /d/IT2 Tryggheim/it
I have this .htaccess rule: RewriteRule viewshoplatest/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /viewshoplatest.php?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10&$11=$12&$13=$14&$15=$16 It should map a URL like
This is one of those things that just makes me feel like an idjut.
I am using this htaccess file. Everything is working fine except that first RewriteRule.
I'm using this .htaccess AuthName Reserved Area AuthType Basic AuthUserFile /opt/bitnami/apache2/htdocs/k4demo60/.htpasswd AuthGroupFile /opt/bitnami/apache2/htdocs/k4demo60/.htgroup <FilesMatch

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.