Jump to content

Friendly URLs include index.php with my .htaccess


Go to solution Solved by Matt,

Recommended Posts

Posted (edited)

Hello.

I have problems with index.php in my urls.

I have the htaccess file and select "Rewrite URLs".

The problem is:

URL in browser -> Destination
mydomain.com/index.php ->  mydomain.com/index.php

mydomain.com/index.php/ ->  mydomain.com

mydomain.com/forum/topic/index.php ->  mydomain.com/

mydomain.com/forum/topic/ -> mydomain.com/forum/topic/

Please, can someone check my text to see if there is something wrong?

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RedirectMatch ^/forum/(.*?)/?$ /$1


# CUSTOM URLs by DawPi

#Categories & Forums
RewriteRule ^([0-9]+)-([a-zA-Z0-9_-]+).html$ viewforum.php?id=$1 [r=301,nc,l]
RewriteRule ^forum/([0-9]+)-([a-zA-Z0-9_-]+).html$ viewforum.php?id=$1 [r=301,nc,l]

#Profiles
RewriteRule join-club/([0-9]+)-([a-zA-Z0-9_-]+)/profile.html profile.php?id=$1 [r=301,nc,l]

#Topics (second and so on page)
RewriteRule ([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+).html?start=([0-9]+) viewtopic.php?id=$3&st=$5 [r=301,nc,l]

#Topics
RewriteRule ([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+).html viewtopic.php?id=$3 [r=301,nc,l]

# END #


# ----------------------------------------------------------------------
# | ADDED BY ME                                                         |
# ----------------------------------------------------------------------

<Files .htaccess>
Require all denied
</Files>

#Allow conections only bu mydomain.com and alias
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain\.es$
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain2\.com$
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain\.eu$
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain\.info$
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain\.com.es$
RewriteCond %{SERVER_NAME} !^(www\.)?mydomain\.es$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ - [F]



RewriteCond %{HTTP_HOST} ^www.mydomain2.com [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301] 
RewriteCond %{HTTP_HOST} ^mydomain2.com [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301] 
RewriteCond %{HTTP_HOST} ^www.mydomain.eu [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301] 
RewriteCond %{HTTP_HOST} ^mydomain.eu [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.mydomain.info [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301] 
RewriteCond %{HTTP_HOST} ^mydomain.info [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.mydomain.com.es [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301] 
RewriteCond %{HTTP_HOST} ^mydomain.com.es [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.es/$1 [L,R=301]


#Clickjacking attack
#Header append X-FRAME-OPTIONS "SAMEORIGIN"

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mydomain.es/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.es$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain2.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain2.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.es/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.es$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain2.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain2.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mydomain.es/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mydomain.es$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mydomain.es/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mydomain.es$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|doc|pdf|mp3|mp4|mov|avi)$ - [F,NC]

# php -- BEGIN cPanel-generated handler, do not edit
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Many Thanks.

Edited by pequeno
Posted

If I just put this code, it doesn't work either

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

 

  • 2 weeks later...
Posted
45 minutes ago, Marc Stridgen said:

Relooking at this, what exactly is the first one doing?

The topic one would not work, as thats not actually a URL even without rewrites. 

I will privately send you the URL that corresponds to mydomain.com

I put it this way so as not to reveal my domain.

Posted

Sorry. I don't know what I have to answer. I am a bit lost with the English language. What do you need to know exactly? 

Redirects should remove index.php and I see that not happening.

Posted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Try and put this at the bottom of your htaccess file

Posted
On 12/10/2021 at 9:42 PM, Adlago said:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Try and put this at the bottom of your htaccess file

Thanks.

It's the code I use, provided by IPS in the ACP, and it doesn't work ... I can't remove index.php from the url

Posted
3 hours ago, pequeno said:

Thanks.

It's the code I use, provided by IPS in the ACP, and it doesn't work ... I can't remove index.php from the url

If your site is in forum directory, put in this directory htaccess file with this code

Posted
6 hours ago, Adlago said:

If your site is in forum directory, put in this directory htaccess file with this code

Forum is in root /

14 minutes ago, Randy Calvert said:

The only way that htaccess code will work is if your hosting provider has mod_rewrite enabled. Have you verified that module is installed and working correctly?

Installed and enabled.

Posted
Marc
This post was recognized by Marc!

"Thank you for your help"

Adlago was awarded the badge 'Helpful' and 10 points.

32 minutes ago, pequeno said:

Forum is in root /

Installed and enabled.

Test - add this

RewriteCond %{THE_REQUEST} \ /(.+/)?index\.([^/]+)(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.([^/]+)$ /%1 [NC,R=301,L]

 

Posted

Again, you havent actually answered what is happening on the first item when you visit with /index.php

It does sound here like there may be an issue with rewrites on your server

Posted
1 hour ago, Marc Stridgen said:

Again, you havent actually answered what is happening on the first item when you visit with /index.php

It does sound here like there may be an issue with rewrites on your server

Indeed, if I put the address with index.php in the browser, it is not removed and the destination is the same.

On 11/26/2021 at 10:19 PM, pequeno said:

URL in browser -> Destination
mydomain.com/index.php ->  mydomain.com/index.php

The redirect to remove index.php does not apply in my case.

It only applies if I put a / at the end.

On 11/26/2021 at 10:19 PM, pequeno said:

mydomain.com/index.php/ ->  mydomain.com

The same happens in topics that have index.php at the end.

On 11/26/2021 at 10:19 PM, pequeno said:

mydomain.com/forum/topic/index.php ->  mydomain.com/

mydomain.com/forum/topic/ -> mydomain.com/forum/topic/

Thanks @Adlago

13 hours ago, Adlago said:

Test - add this

RewriteCond %{THE_REQUEST} \ /(.+/)?index\.([^/]+)(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.([^/]+)$ /%1 [NC,R=301,L]

 

I will test.

Posted
On 12/13/2021 at 9:53 PM, pequeno said:

Works Perfectly! Thanks.

 

On 12/13/2021 at 12:58 PM, Marc Stridgen said:

Please let us know if that does not resolve your issue

 

On 12/12/2021 at 11:03 PM, Adlago said:

Test - add this

RewriteCond %{THE_REQUEST} \ /(.+/)?index\.([^/]+)(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.([^/]+)$ /%1 [NC,R=301,L]

 

NOT SOLVED!

Works removing index.php but when I try to upload a embed video or image, I obtain this error:

Quote

The link could not be embedded because of an unexpected error: forbidden. The CSRF protection key did not match. This may indicate a plugin or theme is out of date. Please contact technical support for more information.

 

Posted
2 hours ago, Marc Stridgen said:

Please ensure all access details on file are up to date, then we can take a look. Also please ensure you are using only our default htaccess

Thanks @Marc Stridgen

Please, let me know the IPS IPs for add to firewall whitelist.

Posted
On 12/15/2021 at 7:07 PM, Marc Stridgen said:

Please ensure all access details on file are up to date, then we can take a look. Also please ensure you are using only our default htaccess

Have you checked It? 

I need to restore my custom htaccess.

Thanks.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...