0

I've installed Wordpress in root directory and CodeIgniter in sub directory. I'm having the following set of urls:

  1. http://www.example.com/about-us (Wordpress)
  2. http://www.example.com/sub-dir/users/login (CodeIgniter)
  3. http://www.example.com/sub-dir/merchant/login (CodeIgniter)

Now I want to remove sub-dir only from second url and the remaining urls should work as they are.

Here is .htaccess code in root directory (Wordpress)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /yevma/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /yevma/index.php [L]
</IfModule>
# END WordPress

Any help would be appreciated!

7
  • Could you please elaborate Now I want to remove sub-dir only from second url more please? You mean you want to restrict someone from accessing this url OR you want to redirect it to some other url? Commented Jan 26, 2020 at 8:35
  • To confirm... have you already removed the sub-dir from all the instances of these URLs within your app? Otherwise, this is a Codeigniter question, not .htaccess? Commented Jan 26, 2020 at 13:44
  • @RavinderSingh13 the first url is of wordpress CMS and other two are of codeigniter application. So with change in .htaccess I want to access second url like example.com/users/login and other two should work as they are. Also I added my .htaccess file in question.Please let me know if it need more explanation. Thanks! Commented Jan 26, 2020 at 15:52
  • @MrWhite No, I've not removed but want help to remove it. Let me explain it little more: The first url is of wordpress CMS and other two are of codeigniter application. Now if I remove sub-dir from url the server assumes that it's a wordpress url so gives 404 error. As it not even calling codeIgniter app so I think it can be handled via .htaccess. Commented Jan 26, 2020 at 16:06
  • Well, you need to actually remove the /sub-dir from the URLs in your Codeigniter URLs - in your web application (HTML source), otherwise they are still going to be visible in the HTML of your page (and to your users). You don't use .htaccess for this bit. You would then use .htaccess to internally rewrite the request back to /sub-dir (thus hiding /sub-dir from the user). Do you literally only have those 2 Codeigniter URLs... /users/login and /merchant/login? Also, it depends how you have configured Codeigniter to route requests, ie. the value of the uri_protocol config. Commented Jan 26, 2020 at 16:18

1 Answer 1

1

Your question is vague, we can only assume that you are trying to publish the resource currently reachable via that second URL under a different, shorter URL.

Also assuming that this will not somehow collide with other resources this should point you into the right direction:

RewriteEngine on
RewriteRule ^/?users/login$ /sub-dir/users/login [QSA,END]

Note however tht this might cause issues with the internal references used in those applications you have, since you break the structure with such a single redirection.

In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.

This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

Sign up to request clarification or add additional context in comments.

7 Comments

Yes, I want to access example.com/sub-dir/users/login under a shorter url. Unfortunately your code has no impact on urls. I added some explanation and .htaccess code to the question. Please let me know if it need more explanation. Also I'm looking for the other option. Thanks for your time.
Can you please tell me how I can set these rules in http servers host in Cpanel? Or I have to contact hosting support team?
"has no impact on URLs"... this reads as if you expect rewriting to somehow magically modify the references in the content you send out. But that is not the case, rewriting is applied to incoming requests. And for that the rule certainly works if implemented correctly and if enabled.
I have very little experience with CPanel, never understood why people use such.
I've edited question and added my .htaccess there. I browsed the url few times but result was same. Where I can set these rules in http servers host. Please don't mind, I'm week in such configuration and it's always a nightmare.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.