Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Apache mod_rewrite questions

Posted on 2014-03-21
Medium Priority
Last Modified: 2014-04-04
I have a site on a shared hosting server that is using .htaccess to redirect to and to rewrite to (the chs  subdirectory is my doc root).

I believe that having a cgi-bin directory under my apache doc root is a bad idea, but my hosting company appears unconcerned and I can't see that I have a choice. Let me know what the risks are, thanks.

I tried using apache mod_rewrite to rewrite the url to my scripts directory: (current url) (desired url)

with this apache configuration:

DocumentRoot /home/user/path/to/chs
Alias /abc /home/user/path/to/chs/my_scripts

<Directory /home/user/path/to/chs/my_scripts>
    RewriteEngine On
    RewriteRule ^/abc/(.*)$ /my_scripts/$1
    AllowOverride All

Open in new window

but the urls to my scripts remain unchanged and no errors appear in the logs (with level  warning). I'm trying to accomplish something covered under and can't see what I'm missing. Help.
Question by:sara_bellum
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 15

Accepted Solution

Insoftservice earned 1500 total points
ID: 39944910
Little confused with your question.
"I have a site on a shared hosting server that is using .htaccess "

and you have changed apache config.
Did you changed the conf file from your hosting provider?

    RewriteRule ^/abc/(.*)$ /my_scripts/$1
Allows the browser to accept the url which has "abc" within it instead of "my_scripts".
Try to create url replace with my_scripts and try whether you are getting any error.
As rewrite would not replace your url but it allows you to use your desired url considering your rewrite rule is right.


If you are able to use you new url it implies that your rewrite rule is perfect.
1>Try to change url link wherever it has "myscripts" within it .
if you are getting "mysripts" within the page then do 301 redirect to "abc" so that your users won't get two different url and even google does not have any issue for its SEO

Author Comment

ID: 39946404
Great advice, thank you! It worked perfectly on localhost, where I can edit the site file directly in apache. I hadn't thought of testing the url manually and was following links from previous pages. Once I changed those links as you recommended, all was well.

Unfortunately, mod_rewrite implementation in the htaccess files on the remote server fails and I haven't figured out how to make it work.  Any tips are appreciated.

Author Comment

ID: 39946664
I'm still confused about how this works: in my localhost apache site config directory instructions that correctly implement the url rewrite, the syntax is:
RewriteRule: actual-path requested-path

But in your htaccess guidance this order is reversed:
RewriteRule: requested-path actual-path
Please confirm the path order that htaccess uses for rewrites, thanks.

To recap, htaccess is now enabled on my localhost and my htaccess file is under doc root (my hosting provider checked for htaccess errors under doc root only):
RewriteBase: /abc (desired path)
RewriteRule /abc  /my_scripts

Apache looks for the file under the desired url:
/path/to/docroot/abc/text.cgi and cannot find it - the actual path is
/path/to/docroot/my_scripts/text.cgi - if I change the url back to the actual path it works on localhost but on the remote server I get an apache core error with rewrite enabled.

I tried reversing this order in localhost htaccess:
RewriteBase /my_scripts (actual path)
RewriteRule /my_scripts /abc
but the error is the same. Apache simply compares the requested url to the actual path and no rewrite occurs.

The syntax remains unchanged from my earlier post:
RewriteBase /abc/
RewriteRule ^/abc/(.*)$ /my_scripts/$1 [L]

Author Comment

ID: 39976928
This turned out to be more difficult than anticipated. Initially, I got this rule to work in my apache doc root .htaccess file:
RewriteRule ^desired-path/(.+)$ /actual-path/$1

but then I decided that I needed to remove the joomla subdirectory from my urls (joomla was installed in a subdirectory of my apache doc root). This required that I  move the joomla htaccess file under my apache doc root and edit this file under the 'custom redirects' section.  It also required that the configuration.php file $live_site variable reflect the desired url.

I also installed an SSL certificate for the domain, again editing the configuration.php  $live_site variable to reflect https connections.

The url now appears secure and omits the joomla subdirectory as intended, but the rewrite rule for my script directory fails. Also, requests for are not redirected to, although www redirects worked when I was using http connections, due to the way secondary domains are configured for multiple-domain SSL certificates with my hosting service.

So it's work in progress. But it's time to close this.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question