Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_rewrite rules and content negotiation
    primarykey
    data
    text
    <p>I am relatively new to mod_rewrite, but have a site which I would like to have "pretty urls." Similarly to SO :).</p> <p>I am attempting to have things like: "<a href="http://www.whatever.com/search/test" rel="nofollow noreferrer">http://www.whatever.com/search/test</a>" get rewritten to "<a href="http://www.whatever.com/search.php?q=test" rel="nofollow noreferrer">http://www.whatever.com/search.php?q=test</a>" and have had some limited success. I believe that content negotiation is getting in my way...</p> <p>For starters here's my test .htaccess file:</p> <pre><code>RewriteEngine on RewriteBase /~user/mysite/ RewriteRule ^search$ search/ [R] RewriteRule ^search/([^/]*)/?$ search.php?q=$1 [L] </code></pre> <p>Which unfortunately, <em>does</em> redirect to search.php, but does not pass my param in the q variable. However this <em>does</em> work:</p> <pre><code>RewriteEngine on RewriteBase /~user/mysite/ RewriteRule ^search$ search/ [R] RewriteRule ^search/([^/]*)/?$ s.php?q=$1 [L] # here i've renamed the search.php to s.php to dodge the content negotiation that is happening.. </code></pre> <p>In fact, if I remove the rules all together, I get the same result as with the first version of the file. So my conclusion is that since apache is happily redirecting "foo" to "foo.php" even without any mod_rewrite rules, that it must be the content negotiation that is taking care of it. (This is further verified by the fact if I renamed my foo.php to foo.html, it still will find the file if i just go to "foo").</p> <p>So, the question is. How do I properly use mod_rewrite with regard to content negotiation? Can I disable it for a particular file? Is there a way to ensure that my mod_rewrite rules happen before the content negotiation happens?</p> <p>If it is relevant, here is the conf file for the mod_userdir part of my apache conf (this test site is in my user's homedir/public_html):</p> <pre><code># Settings for user home directories &lt;IfDefine USERDIR&gt; &lt;IfModule userdir_module&gt; # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. Note that you must also set # the default access control for these directories, as in the example below. UserDir public_html # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. &lt;Directory /home/*/public_html&gt; AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec &lt;Limit GET POST OPTIONS&gt; Order allow,deny Allow from all &lt;/Limit&gt; &lt;LimitExcept GET POST OPTIONS&gt; Order deny,allow Deny from all &lt;/LimitExcept&gt; &lt;/Directory&gt; # Suexec isn't really required to run cgi-scripts, but it's a really good # idea if you have multiple users serving websites... &lt;IfDefine SUEXEC&gt; &lt;IfModule suexec_module&gt; &lt;Directory /home/*/public_html/cgi-bin&gt; Options ExecCGI SetHandler cgi-script &lt;/Directory&gt; &lt;/IfModule&gt; &lt;/IfDefine&gt; &lt;/IfModule&gt; &lt;/IfDefine&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload