Jump to content

Recommended Posts

Hello every body

 

Currently I'm facing a new prbel with .htaccess.

 

I've used this code to remove the .php extention and add a trailing '/' at the end.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{HTTP_HOST} !^www.superioradsmedia.com$ [NC]
RewriteRule ^(.*)$ http://www.superioradsmedia.com/$1 [L,R=301]

Everything is working fine except two things

 

1) If I use an image location like "www.abc.com/images/abc.jpg" it does'nt show up.. But if I use 'http://' in front of it it shows the image...

 

2) Suppose I have a directory in my root directory like 'new_folder' which contains an index.php page

 

If i access like this

 

www.abc.com/new_folder       -------------------> It gives me 404 error...

 

But if I use    

 

www.abc.com/new_folder/index.php   ---------------------> it works...

 

 

ANy help will be greatly appreciated....

 

Thank you...

Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/
Share on other sites

1) If I use an image location like "www.abc.com/images/abc.jpg" it does'nt show up.. But if I use 'http://' in front of it it shows the image...

Always use an absolute path. That could be with the "http://", or you could do it more easily with just "/images/abc.jpg".

 

2)

Try adding a

DirectoryIndex index.php
Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488460
Share on other sites

@requinix

 

still not working, showing the same error....

 

404 not found

 

've change the file as u have said

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

DirectoryIndex index.php

Plz help me/...... :)

Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488598
Share on other sites

I don't see how since none of the other RewriteRules will match it.

# won't match because it doesn't end in a slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php

# doesn't contain slash, doesn't end in a slash
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

# has a file extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

# irrelevant to this discussion
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488651
Share on other sites

Right. I put comments into the one you already had. I'm saying I don't see any opportunity for a loop. "/new_folder" will match the first set and redirect to "/new_folder.php". That then won't match any of the four sets and so... no loop.

 

Could you just try it and see what happens?

Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488655
Share on other sites

If I add [L,R] in each RewriteRule

 

then it redirects me to the another url

 

Example

 

I want to visits

 

www.example.com/new_folder

 

it took me to this url

 

http://www.example.com/home3/superior/public_html/new_folder.php

 

 

Is there anything that could solve the problem ????

 

plz help...

Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488674
Share on other sites

Huh. It did exactly what I said it would.

 

The .php is being added because of the first rewriting rules

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
because "/new_folder" isn't a file. It should be ignoring directories, which you can do with

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1.php
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488755
Share on other sites

  • 3 weeks later...

I don't have time to actually help you but here is a .htaccess file i am currently using:

DirectoryIndex board/index.php

############################################################################################

RewriteEngine on
########################## Redirect name/firstname/lastname ################################
RewriteCond %{REQUEST_URI} user/(.*)/(.*)/
RewriteRule user/(.*)/(.*)/ %{DOCUMET_ROOT}/board/test.php?firstname=$1&lastname=$2

RewriteCond %{REQUEST_URI} /user/(.*)/
RewriteRule user/(.*)/ %{DOCUMET_ROOT}/board/test.php?firstname=$1

RewriteCond %{REQUEST_URI} /user
RewriteRule user/ %{DOCUMET_ROOT}/board/test.php

RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/
#############################################################################################

RewriteCond %{REQUEST_URI} BETA/ [NC]
RewriteRule BETA/ %{DOCUMET_ROOT} [NC]

RewriteCond %{REQUEST_URI} construction/ [NC]
RewriteRule construction/ %{DOCUMET_ROOT}/board/ECT/SITE_STATUS_/construction.php [NC]

RewriteCond %{REQUEST_URI} ACCESS_DENIED/ [NC]
RewriteRule ACCESS_DENIED/ %{DOCUMET_ROOT}/board/ECT/SITE_STATUS_/ACCESS_DENIED.php [NC]

My directory is like this:

-htdocs

    -board

        -index.php

        -construction.php

        -ACCESS_DENIED.php

   -css

   -php

    -js

    -resources

 

 

Hope this helped

 

 

Also press the Thanks on 

requinix Edited by Richard_Grant
Link to comment
https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1490310
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.