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]
Community
  • 1
  • 1
Summer Developer
  • 2,056
  • 7
  • 31
  • 68
  • 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` – Joe Nov 01 '16 at 22:10
  • @thickguru I changed it because the only urls I want to rewrite are those beginning with `/thanksgiving/` – Summer Developer Nov 01 '16 at 22:21

1 Answers1

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/ ) .

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Doesn't work, does the second leading slash need to be nixed as well? – Summer Developer Nov 02 '16 at 16:18
  • @SummerDeveloper Add this before your wp or other rewriteRules. – Amit Verma Nov 02 '16 at 17:03
  • Still a 404. Can you double check your `RewriteRule` line? It still looks slightly off to me but I can't pin down why... – Summer Developer Nov 02 '16 at 17:20
  • @SummerDeveloper you are right. there was a slight typo. I have removed the trailing slash. – Amit Verma Nov 02 '16 at 17:27
  • Still a 404, which loads using the Wordpress template btw so it isn't being caught before the Wordpress rules and goes straight to a Wordpress 404. – Summer Developer Nov 02 '16 at 17:38
  • I'm editing the htaccess in the root directory, `/thanksgiving` has its own htaccess that handles Laravel routing (I have a Laravel and a Wordpress app side by side on shared hosting), not ideal I know but this is the environment the client has forced. – Summer Developer Nov 02 '16 at 17:43
  • I don't believe the `/thanksgiving` htaccess is causing conflicts but I can edit and post it if you think that would be helpful. – Summer Developer Nov 02 '16 at 17:43
  • Well, I went ahead and included it in my question, please see edits. I don't think the issue is there though... still think its a regex issue in your line... – Summer Developer Nov 02 '16 at 17:50
  • I think your /thanksgiving/.htaccess is conflicting with the uri . Try placing this rule in thanksgiving/htaccess instead of the root. Try the updated rule. – Amit Verma Nov 02 '16 at 17:53
  • 2
    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! – Summer Developer Nov 02 '16 at 17:57