@dklynn ; would also suggest NOT using (.*), and instead only capture the characters you want. Such as ([a-zA-Z0-9-]+), which captures letters (upper and lowercase), numbers, and the hypen (-).

dklynn
—
2012-09-24T08:33:44Z —
#4

cp,

You must've been "abused" by me as you're doing quite well with your mod_rewrite responses! :tup:

md1,

I believe that your problem (aside from the obvious (.*))was with the redirection. I must assume that your .htaccess is in your DocumentRoot so the redirection will be relative to that. The problem is that you do not need to specify the current directory with the ./, all you need is author.php.

Tip: I try to put all my mod_rewrite code in the DocumentRoot's .htaccess so I don't have to consider directory levels (except relative to the DocumentRoot, of course). A second tip (a twofer, how about that!) is to use the R=301 flag (along with the Last flag) so you can see the redirection you've made. At least that would have shown you something really weird and would have forced you to look at the redirection again and you may have noticed the level change.

WARNING: When you change the directory level, you will create a directory offset for any embedded relative links resulting in the loss of css, js and image links (relative to author.php's location in the DocumentRoot). I'll let you read my signature's tutorial to discover the two options to resolve this problem.

Regards,

DK

cpradio
—
2012-09-24T09:38:53Z —
#5

dklynn said:

cp,

You must've been "abused" by me as you're doing quite well with your mod_rewrite responses! :tup:

The nightmares were terrible, I finally got over them until a few threads ago No, I really glad that I've run into you in regards to mod_rewrite, I've learned a lot (still have more to learn, but that's why I try).

dklynn
—
2012-09-24T21:20:29Z —
#6

cp,

:rofl: Whew!

As for mod_rewrite, all it takes is a little experience (and answering member questions for too many years).

MultiViews allows a URI to be hijacked if there is an identical filename in the path, i.e., author.php and author/ where author.php will actually be run. I ensure that it's off (-MultiViews) as you can get really weird results if you're not careful.

You neither showed us your test URI nor the result of an R=301 flag (used for testing, it will display the redirection) but that's about the only thing that could have hijacked your URI UNLESS you have other mod_rewrite (or mod_alias) code in your .htaccess (which should also be displayed for reasonable help).

Regards,

DK

cpradio
—
2012-09-27T11:32:46Z —
#10

dklynn said:

md1,

MultiViews allows a URI to be hijacked if there is an identical filename in the path, i.e., author.php and author/ where author.php will actually be run. I ensure that it's off (-MultiViews) as you can get really weird results if you're not careful.

You neither showed us your test URI nor the result of an R=301 flag (used for testing, it will display the redirection) but that's about the only thing that could have hijacked your URI UNLESS you have other mod_rewrite (or mod_alias) code in your .htaccess (which should also be displayed for reasonable help).

Regards,

DK

Thank you! I was playing around with this last night and got weird results using /author/testing becuase I had an author.php, and I eventually found that renaming the file to author2.php worked, and so did using -MultiViews, but I didn't have time to research why it worked yet. Your explanation even helped me

dklynn
—
2012-09-27T22:11:46Z —
#11

cp,

Thanks! I think SitePoint should bring you on staff! Oh, wait, they have :rofl: You're doing very well so keep learning (and visit apache.org for the straight skinny on their modules and core directives - I do all the time!).

Regards,

DK

maxdream01
—
2012-09-27T23:04:33Z —
#12

Hi everyone, I tried placing -MultiViews in the code and it stopped the the server from trying to go to /author/author-name/index.php, but now I'm receiving a 300 multiple options error, trying to make me go to author.php/author-name/.

I do not have any other mod_rewrite commands in .htaccess.

Thanks for the help,Maxdream01

cpradio
—
2012-09-27T23:22:47Z —
#13

I had to change the rewrite rule to the following to support hypens and a possible ending slash

What URL were you testing? I did get a 404 for testing /author/author-name/index.php, but it works for /author/author-name/ and /author/author-name

maxdream01
—
2012-09-28T00:03:22Z —
#16

I recieved a 404 for both /author/author-name and /author/author-name/

dklynn
—
2012-09-29T02:34:28Z —
#17

maxdream01 said:

I recieved a 404 for both /author/author-name and /author/author-name/

md1,

There is no reason for those URIs not to work (except for the comment below about trailing /'s). Add the flags I added to cp's code (after confirming that you have author.php in your DocumentRoot (the same directory as this .htaccess).

cpradio said:

I had to change the rewrite rule to the following to support hypens and a possible ending slash

Optional trailing will (almost) always kill relative links in your scripts so, unless you're willing to code absolute links or add the <base> meta tag to the author.php script, it's best not to allow optional /'s! In addition, the {REQUEST_FILENAME} is the variable which is commonly used to test files and directories. I think that {SCRIPT_FILENAME} does give the same answer but I'd have to go look it up and I'm swamped for time right now.

both,

The flags can be very useful! In this case, the R=301 flag will tell Apache to display the redirection (to help discover the reason for the 404) and can be removed before the code goes to the production machine. Obviously, the Last flag tells mod_rewrite to restart the next pass through the code.

Regards,

DK

maxdream01
—
2012-09-29T03:33:19Z —
#18

Hi Dk,

This change gave me very strange results, if i try to go to /author/author-name/ it tries to take me to /author.php/author-name/index.php, which does not exist, and if i try to type in /author/author-name it tries to take me to the full server root, e.g. http://www.site.com/******/homepages/*/********/htdocs/rfid/author.php?name=ari-boyarsky, this is the actual server root where the files are located, its a shared server, the * represent information I can't disclose here, but its just a string of numbers that identifies each site on the server.

Thanks,Maxdream01

dklynn
—
2012-09-29T05:16:48Z —
#19

md1,

Now we're getting somewhere!

Okay, author/author-name/ identifies a directory and DirectoryIndex is obviously set for index.php {others? none were found} so it gave you author/author-name/index.php as it is supposed to do (I trust that you removed the optional trailing / for the reasons above).

Now, the server root is a problem when /author.php was not requested (when it doesn't find author.php in the server root, it's supposed to look in the domain's DocumentRoot, which it has done, but it's supposed to relative to the DocumentRoot, not the server root). I've had that same problem (on my WinDoze test machine). Many others have had that problem, too, and the only way I/we have found to resolve that problem is to restart Apache. Give that a try as it should restore Apache to full (and correct) functioning.

Regards,

DK

maxdream01
—
2012-09-29T13:37:03Z —
#20

DK,

I don't believe i have the power to restart apache, firstly the web host the client is using is 1and1, which uses cgi not apache, and even if it did use apache i do not believe i would have the power to restart apache anyway because it is a shared server.