Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent of which URL the user supplied with the request he should finally see the canonical one only.
Solution:
We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and fix a missing trailing slash for /u/user.
so I setup apache 2.2.4 and use the default configuration file (httpd.conf) enable the user configuration file, delete the "#" befind "Include extra/httpd-user.conf"
I add something to httpd.conf file like this
Code:
RewriteEngine On
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/u/([^/]+$ /$1/$2/ [R]
As same the apache manual, but it isn't work fine.
I got some error info in log file
Hi guy, thank you
it seem I lost the ) when I post it
I use the rule that you give me
RewriteEngine On
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/u/([^/]+)/(.*)$ /$1/$2/ [R]
it change /~user to /user//
I copy from the manual RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/u/([^/]+)$ /$1/$2/ [R]
it change /~user to /u/user/ OK
but I got 404 error as before.
when I put http://<server>/~user
the access.log display like these 192.168.254.1 - - [09/Feb/2009:01:52:55 +0800] "GET /~user HTTP/1.1" 302 219
192.168.254.1 - - [09/Feb/2009:01:52:55 +0800] "GET /u/user/ HTTP/1.1" 404 207
I put http://<server>/u/user
the access.log display 192.168.254.1 - - [09/Feb/2009:01:54:18 +0800] "GET /u/user/ HTTP/1.1" 404 207
the httpd.conf like below:
Code:
RewriteEngine On
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/u/([^/]+)$ /u/$1/$2/ [R]
the url display is correct, but it seem not correct content.
I think maybe need alias, but if use alias why need rewrite?
thank you
erverAdmin you@example.com
DocumentRoot "/opt/httpd/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/opt/httpd/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog logs/error_log
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog logs/access_log common
</IfModule>
<IfModule alias_module>
Alias /u/* /home/*/public_html
ScriptAlias /cgi-bin/ "/opt/httpd/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/opt/httpd/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
Include conf/extra/httpd-userdir.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
RewriteEngine On
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/u/([^/]+)$ /u/$1/$2/ [R]
httpd-userdir.conf
Code:
UserDir public_html
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
without rewrite when I put http://<server>/~user in firefox the access log
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.