1

I looked at this: htaccess remove index.php from url but it didn't work and in the comments there seems to be disagreement on the top answer.

If I type in http://www.example.com/thanksgiving/index.php/getThankyou I get the page I want served.

If I type in http://www.example.com/thanksgiving/getThankyou I get a 404.

What I've tried in my htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/thanksgiving/(.*)/$ /thanksgiving/index.php/$1 [L]
</IfModule>

How do I do it so /thanksgiving/getThankyou/ or any url starting with /thanksgiving in the url leads to the proper resource being served? Again, it is currently available when index.php is in the url.

I also tried: RewriteRule ^/thanksgiving/[^/]*/$ /thanksgiving/index.php/$1 [L] but that didn't work either...

Edit: It seemed part of the htaccess is being set by wordpress and may be conflicting with the desired behavior above:

The wordpress part of the same htaccess is:

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

Is this interfering? How do I reconcile this with the /thanksgiving/ urls which are not part of the Wordpress application?

Edit:

The above only pertains to the root (public_html) htaccess, below is the htaccess in /thanksgiving/ itself, please analyze for conflicts, thanks for all your help!

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Do not change this line. 
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 

# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/thanksgiving/ 

# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /thanksgiving/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ thanksgiving/index.php [L]
2
  • That link to the other answer is correct. I'm not sure why you've changed the RewriteRule the way you have. Change it back to RewriteRule ^(.*)$ /index.php?/$1 [L]. It also does not need to be between the IfModule. Should just work using RewriteEngine On Commented Nov 1, 2016 at 22:10
  • @thickguru I changed it because the only urls I want to rewrite are those beginning with /thanksgiving/ Commented Nov 1, 2016 at 22:21

1 Answer 1

1

You need to remove the leading slash from your rewrite pattern :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:thanksgiving/)?(.*)$ /thanksgiving/index.php/$1 [L]
</IfModule>

Otherwise the rule will accept the uri starting with a double leding slash (ie : //thanksgiving/ ) .

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

10 Comments

Doesn't work, does the second leading slash need to be nixed as well?
@SummerDeveloper Add this before your wp or other rewriteRules.
Still a 404. Can you double check your RewriteRule line? It still looks slightly off to me but I can't pin down why...
@SummerDeveloper you are right. there was a slight typo. I have removed the trailing slash.
Thank you so much. You are awesome! You should really set up a link on your profile for donations, your patience and intelligence need to be rewarded!
|

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.